Alert(); and prompt(); in Javascript over ride other commands

I have noted that

<script> document.write("hello"); alert("bye"); </script>

That the alert bye appears first. Try it and see by placing it in a html page mid body.

Is. It because the page has not been fully parsed?

1 Like

Hi there laurentkitecb,

that does not happen for me. :unhappy:

coothead

This is a browser specific functionality. Some browsers wait till the document is loaded before any messages are displayed and some display when encountered. Things like this is when browser testing comes in handy.

1 Like

Well it must happen for modern browsers. I used chrome the latest on a Mac and IE on Windows 10

Well it must happen for modern browsers. I used chrome the latest on a Mac and IE on Windows 10

Yep, I just duplicated it on Chrome on a Mac.

@jgetner is most likely right because document.write() is a blocking call and should be rendering first.

It’s been so long that I’ve been using createElement, appendChild et al. instead of write I’m a bit surprised modern browsers would still support it at all.

It sounds like you want “close”

Once you have finished writing, it is recommended to call document.close(), to tell the browser to finish loading the page.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.