I’ve written a bookmarklet which injects an external javascript just before the closing body tag.
The injected script contains two lines:
document.write("");
alert("hello");
The alert works.
The document.write has no effect.
What gives? This should clear the page, but the page remains unchanged.
If you need to overwrite the entire document with an empty string. you need to call
document.writeinwindow.onloadhandler:When the page is rendering
document.writejust outputs the string where it is called, but after the page load it replaces the document with the string.or call
document.body.innerHTML = '';