Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    May 2005
    Posts
    59
    Thanks
    3
    Thanked 0 Times in 0 Posts

    showModalDialog() and asynchronous code

    Is it possible to execute showModalDialog() asychronously?

    I'm doing a test page right now, testing out both setTimeout() and setInterval and noticed that if I open a popup using showModalDialog(), both setTimeout() and setInterval pause while the modal popup is visible.

    Here's the two files I'm experimenting with right now:

    file1.htm
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function startMonitoring() {
     window.setInterval('advanceTwo()',1000);
     advanceOne();
    }
    function startPopup() {
     showModalDialog("pop.htm");
    }
    function advanceOne() {
     var x = document.getElementById('one');
     x.value = x.value * 1 + 1;
     setTimeout('advanceOne()',1000);
    }
    function advanceTwo() {
     var x = document.getElementById('two');
     x.value = x.value * 1 + 1;
    }
    </script>
    </head>
    <body>
    <p><input id="one" type="text" value="0" /></p>
    <p><input id="two" type="text" value="0" /></p>
    <p><button onClick="startMonitoring()">Monitor in page</button></p>
    <p><button onClick="startPopup()">Monitor in popup</button></p>
    </body>
    </html>
    pop.htm
    Code:
    <html>
    <head>
    <script type="text/javascript">
    function startMonitoring() {
     advanceOne();
     window.setInterval('advanceTwo()',1000);
    }
    function advanceOne() {
     var x = document.getElementById('one');
     x.value = x.value * 1 + 1;
     setTimeout('advanceOne()',1000);
    }
    function advanceTwo() {
     var x = document.getElementById('two');
     x.value = x.value * 1 + 1;
    }
    </script>
    </head>
    <body onLoad="startMonitoring()">
    <p><input id="one" type="text" value="0" /></p>
    <p><input id="two" type="text" value="0" /></p>
    </body>
    </html>
    I launch file1.htm. I click the "Monitor in page" button and watch the values in the input fields tick up. I then click the "Monitor in popup" button. the modal popup appears, and the values tick upward in that window, however the values in the underlying window stop advancing... not what I wanted.

    Can this be done?

    Thanks in advance,
    Darren

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,631
    Thanks
    0
    Thanked 648 Times in 638 Posts
    A modal window stops all of the other windows from getting any CPU at all until the modal window is closed (that is why you can't generate modal windows in browsers other than Internet Explorer which has access into the operating system). Sounds like what you want is a window that keeps the focus (so it stays in front) but is not modal. As far as I am aware the Mozilla based browsers such as Firefox are the only ones to support that option by adding modal=yes into the third option of a window.open()
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •