...

View Full Version : showModalDialog() and asynchronous code



Darren
08-20-2007, 10:56 PM
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
<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
<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

felgall
08-20-2007, 11:07 PM
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()



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum