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

phantasm

Load 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. Doing this will rewrite the page using document.write which will contain an anchor named "link".

In IE8, IE9, Chrome latest when this link is clicked it will not lead to page load.

In Firefox (tested with latest and FF6) clicking the link reloads the original page.

Firefox behavior seems to be incorrect as using anchors should not lead to page loads. If document write is not used clicking on anchors won't lead to page load even in Firefox.

Is there a workaround for this?

The goal would be to use document.write. This sample just simulates that we'd like to load another complete webpage including lot of javascript code with AJAX which needs to run properly after the inclusion.

nmaier

The spec for write() is somewhat unclear in that regard:

Write a string of text to a document stream opened by open().

Unclear being: What should happen if the stream is not open yet/anymore?

Firefox will:

Writing to a document that has already loaded without calling document.open() will automatically perform a document.open call.

As this is effectively creating (read: "loading") a new document, hence a navigation and page load is performed. There is no way around this in Firefox. You could of course file a bug and ask for Chrome/IE parity for the sake of an open web.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why document.write() behaves differently in Firefox and chrome?

From Dev

Subshell created using (...) behaves differently from bash -c '...'

From Dev

Jquery click event on a list works differently in Firefox and other browsers

From Dev

Why does Firefox interpret 100% zoom differently to other browsers?

From Dev

Do Firefox and other browsers do event listeners differently?

From Dev

Jquery click event on a list works differently in Firefox and other browsers

From Dev

JavaScript delete objects behaves differently in different browsers

From Dev

How do I write a function which behaves differently depending on which monad is at the base of the transformer stack

From Dev

CSS 'top' in fieldset behaves differently in chrome and firefox

From Dev

Distinguish Web Browsers From Each Other With Javascript Document Element

From Dev

“read” works as expected in ZSH but behaves differently when using any other shell

From Dev

Safari implementing display:none differently to other browsers

From Dev

OrderBy is sorting differently in Chrome than other browsers

From Dev

opera positions div differently than other browsers

From Dev

OrderBy is sorting differently in Chrome than other browsers

From Dev

'this' behaves differently

From Dev

Tensorflow cond behaves differently from source

From Dev

CSS animation delay behaves differently in Chrome than in IE/Firefox

From Dev

Transforming <svg> element in SVG behaves differently in Chrome, Firefox

From Dev

Plotting a function which behaves differently over different domains in Matlab

From Dev

to know which link is clicked in the previous page using jsp

From Dev

Hubspot how to know from which template a page is created from?

From Dev

How to open popup from Firefox addon (document.write is not working)

From Dev

How to create a title page for a PDF document created using matplotlib

From Dev

IE 10-11 flex-basis property behaves differently than webkit browsers

From Dev

Firefox wraps inline divs, but other browsers do not

From Dev

Googlemaps listener loading fine in firefox but not in other browsers

From Dev

Javascript busted in only Firefox, fine in other browsers

From Dev

Buttons only appearing in Firefox and not in other browsers

Related Related

  1. 1

    Why document.write() behaves differently in Firefox and chrome?

  2. 2

    Subshell created using (...) behaves differently from bash -c '...'

  3. 3

    Jquery click event on a list works differently in Firefox and other browsers

  4. 4

    Why does Firefox interpret 100% zoom differently to other browsers?

  5. 5

    Do Firefox and other browsers do event listeners differently?

  6. 6

    Jquery click event on a list works differently in Firefox and other browsers

  7. 7

    JavaScript delete objects behaves differently in different browsers

  8. 8

    How do I write a function which behaves differently depending on which monad is at the base of the transformer stack

  9. 9

    CSS 'top' in fieldset behaves differently in chrome and firefox

  10. 10

    Distinguish Web Browsers From Each Other With Javascript Document Element

  11. 11

    “read” works as expected in ZSH but behaves differently when using any other shell

  12. 12

    Safari implementing display:none differently to other browsers

  13. 13

    OrderBy is sorting differently in Chrome than other browsers

  14. 14

    opera positions div differently than other browsers

  15. 15

    OrderBy is sorting differently in Chrome than other browsers

  16. 16

    'this' behaves differently

  17. 17

    Tensorflow cond behaves differently from source

  18. 18

    CSS animation delay behaves differently in Chrome than in IE/Firefox

  19. 19

    Transforming <svg> element in SVG behaves differently in Chrome, Firefox

  20. 20

    Plotting a function which behaves differently over different domains in Matlab

  21. 21

    to know which link is clicked in the previous page using jsp

  22. 22

    Hubspot how to know from which template a page is created from?

  23. 23

    How to open popup from Firefox addon (document.write is not working)

  24. 24

    How to create a title page for a PDF document created using matplotlib

  25. 25

    IE 10-11 flex-basis property behaves differently than webkit browsers

  26. 26

    Firefox wraps inline divs, but other browsers do not

  27. 27

    Googlemaps listener loading fine in firefox but not in other browsers

  28. 28

    Javascript busted in only Firefox, fine in other browsers

  29. 29

    Buttons only appearing in Firefox and not in other browsers

HotTag

Archive