javascript - Firefox behaves differently from other browsers if anchors are clicked on a page which was created using document.write. Is there a workaround? -


load 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 page loaded click link. doing rewrite page using document.write contain anchor named "link".

in ie8, ie9, chrome latest when link clicked not lead page load.

in firefox (tested latest , ff6) clicking link reloads original page.

firefox behavior seems incorrect using anchors should not lead page loads. if document write not used clicking on anchors won't lead page load in firefox.

is there workaround this?

the goal use document.write. sample simulates we'd load complete webpage including lot of javascript code ajax needs run after inclusion.

the spec write() unclear in regard:

write string of text document stream opened open().

unclear being: should happen if stream not open yet/anymore?

firefox will:

writing document has loaded without calling document.open() automatically perform document.open call.

as creating (read: "loading") new document, hence navigation , page load performed. there no way around in firefox. of course file bug , ask chrome/ie parity sake of open web.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -