Is it possible to save EventListeners to webstorage?

var entity = document.createElement("a");
entity.addEventListener("click", function(e) {
    play(path, this.id, "audio");
    e.preventDefault();
});

function save() {
    var playlist = document.getElementById("playlist");
    localStorage.setItem("playlist", playlist.innerHTML);
    localStorage.setItem("id", id);
}

This saves the element fine, but when the page is reloaded the listener is gone.

有帮助吗?

解决方案

I doubt it, since LocalStorage can only store strings, and it seems like a bit of overkill to just save an event listener into the LocalStorage object, when you don't know that all of your users will even have the capability.

I would consider a pseudo-element storage, similar to what is discussed here.

其他提示

No, it definitely isn't. localStorage only stores strings, period.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top