ShowModelessDialog - onLoad error - IE 7

MSIE v7 (in my hands) does not open the Modeless dialog box or does not fire the onLoad event if there is a Javascript warning on the landing page. In MSIE v7, the following failure occurs, but everything is fine in v6 (if necessary, a full source zip file is available).

Thank others confirming this and discuss why this should be so.

index.htm (only javascript function shown)

function openDialog(n) { if (typeof(window.showModalDialog) == 'object') { /* Ensure of browser support */ var sURL = 'modeless.htm'; /* Set the URL */ var oWin = window.showModelessDialog(sURL); /* Create new modeless window */ } else { alert('"showModlessDialog" not supported!'); } } 

modeless.htm

 <html> <head> <title>Modeless dialog</title> </head> <body bgcolor="#ff0000" text="#ffffff" onLoad="alert('Modeless is now loaded')"> <center> <h1>Modeless</h1> </center> <script type="text/javascript" language="JavaScript"> /* If the next line is included, it prevents the onLoad event occurring in MSIE v7 */ alert('This alert stops the onLoad event in MSIE v7!'); </script> </body> </html> 
+4
source share
3 answers

IE7 seems to display the correct behavior. HTML is read and parsed sequentially, including scripts. When the parser reaches the javascript warning, it executes it and waits for a return. He can then complete the parsing of the page and raise the onLoad event.

If you want the warning to appear after the page loads, you must handle the onLoad event. You can do this initially:

 window.onload = function() { //do stuff here } 

Or you can do it with any number of javascript libraries, for example jQuery:

 $(document).ready(function() { //do stuff here }); 
+1
source

Are you sure this is not your built-in onload event that stops it? The code below works for me.

INDEX.HTM

 <html> <head> <title>Index</title> <script type="text/javascript" language="JavaScript"> function openDialog() { if (window.showModalDialog) { var sURL = 'Modeless.htm'; var oWin = window.showModelessDialog(sURL); } else { alert('"showModlessDialog" not supported!'); } } function addEventSimple(obj,evt,fn) { if (obj.addEventListener) obj.addEventListener(evt,fn,false); else if (obj.attachEvent) obj.attachEvent('on'+evt,fn); } function removeEventSimple(obj,evt,fn) { if (obj.removeEventListener) obj.removeEventListener(evt,fn,false); else if (obj.detachEvent) obj.detachEvent('on'+evt,fn); } addEventSimple(window, "load", openDialog); </script> </head> <body text="#ffffff"> <h1 align="center">Index</h1> </body> </html> 

Modeless.htm

 <html> <head> <title>Modeless dialog</title> <script type="text/javascript" language="JavaScript"> addEventSimple(window, "load", showAlert); function showAlert() { alert('Modeless is now Loaded'); } function addEventSimple(obj,evt,fn) { if (obj.addEventListener) obj.addEventListener(evt,fn,false); else if (obj.attachEvent) obj.attachEvent('on'+evt,fn); } function removeEventSimple(obj,evt,fn) { if (obj.removeEventListener) obj.removeEventListener(evt,fn,false); else if (obj.detachEvent) obj.detachEvent('on'+evt,fn); } </script> </head> <body text="#ffffff" > <h1 align="center">Modeless</h1> <script type="text/javascript" language="JavaScript"> /* If the next line is included, it prevents the onLoad event occurring in MSIE v7 */ alert('This alert stops the onLoad event in MSIE v7!'); </script> </body> </html> 

Note. For some reason, I need to clear my browser cache in order to get any changes in the updated model window.

0
source

I think there is some confusion about using alert () in the HTML tag of the modeless dialog box. The following points will facilitate the explanation of the observed behavior:

  • Code checks support for modeless dialogue (object detection)
  • If yes, in the above check, proceed to the next step, otherwise display a warning.
  • In a modal dialog, the body of the HTML is loaded by the browser and parsed sequentially, as indicated in another answer .
  • Script tags can appear anywhere in the body, and MS Windows Script Host (JavaScript engine for MSIE) will parse and execute it. Since the warning in the modal dialog box is not in the function, it ends as a global block of code and will be executed immediately when the execution of the Script block is performed by the JS engine.
  • Warnings stop further execution of JavaScript. JavaScript will only resume when the user rejects the warning.
  • The onload handler runs only when the document is fully loaded and displayed. Therefore, the execution of the warning delays the execution of the onload handler until the user rejects the warning and the rest of the document is parsed and displayed.

    An article by the Opera developer community about sync and sync in JavaScript (even though it doesn't talk specifically about IE) is a really useful article to read in this context.

    Update . I tried to run the same code, both from the server (Apache Tomcat) and from the file system. It seems that the described behavior occurs when I open index.html from the file system, and not from the server. The IE zone settings can work here.

0
source

All Articles