Download the following example in different browsers.
<!DOCTYPE html> <html> <body> <a onclick='document.write("text <a href=\"#a\">link</a>");document.close();'>click</a> </body> </html>
When the page is loaded, click the link. This will overwrite the page with document.write, which will contain a binding called link.
In IE8, IE9, Chrome, the last time this link is clicked will not load the page.
In Firefox (tested with the latter and FF6), clicking the link reloads the original page.
Firefox's behavior seems to be wrong, since using anchors should not result in pages loading. If the document is not used, clicking on the anchors will not load the page even in Firefox.
Is there a workaround for this?
The goal would be to use document.write. This example simply mimics the fact that we would like to download another full web page, including a lot of javascript code with AJAX, which should run correctly after inclusion.
source share