Reputation: 11
Does anybody have any idea why the following code will be executed in different order in different browsers? Code is in an external file embedded in a plain HTML page between <body></body>
using <script src="js/filename.js"></script>
.
document.write("This is the first document.write()");
document.write("<br />followed by a second doc.write with br-element before");
document.write("<br /> and a third one doc.write with br before");
alert("now comes an alert() as fourth (will be expected)");
document.write("<br /> then there will be a fifth doc.write after the first alert");
document.write("<br />and a one more (sixth) doc.write after which an alert will be expected");
alert("the second alert at seventh position");
document.write("<br />and now the eight doc.write after the seventh alert");
Chrome executes the alerts at first followed by the docWrites, Edge execute the first 3 docWrite's, then both alerts and then the other docWrite's (also wrong order). Only Firefox execute this code in the right order.
Same behavior is when I execute similar code in developer tool of the browser(s)
for example: write in one line an document.write()
; followed by an alert()
. Chrome will execute the alert()
as first...
Does anyone have any ideas?
Upvotes: 1
Views: 53