I'm doing this but it doesn't work:
window.addEventListener("load", function load(event){
alert('hola');
},false);
window.location.assign("about:blank");
It's a Greasemonkey script. The new location is loaded but the alert is never shown.
I'm doing this but it doesn't work:
window.addEventListener("load", function load(event){
alert('hola');
},false);
window.location.assign("about:blank");
It's a Greasemonkey script. The new location is loaded but the alert is never shown.
By only changing the hash (or fragment) part of the url, then doing whatever it is you want to do, thus:
or thus:
If the document has already loaded,
onload
will not trigger again, so you cannot run it from aload
event. HTML5, offers ahashchange
event, which you could use, thus:Some javascript libraries (I know dojo does) implement
hashchange
or an equivalent for non-HTML5 browsers. In order to take advantage of that, you would need to use that library's convention for registering for events.Once you change the
window.location
, the current instance of your Greasemonkey script is purged. To "run code" after the location change, you need to set the script to trigger on the new page (about:blank
in this case), and then use a flag to signal that the new page was reached via this script redirecting the original page.@include
or@match
directives fire on the new page.GM_setValue()
to set the flag letting the script know it has been deliberately reincarnated.Here is a complete, working script that illustrates the process: