Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Modal popup Window

0.00/5 (No votes)
19 Mar 2006 1  
Creating a modal popup Window

Introduction

Internet Explorer and Mozilla based browsers (FireFox etc.) allow you to make a pop-up window modal. For Internet Explorer, you can use the showModalDialog method. For Mozilla based browsers, you can use window.open with parameter "modal" to open a window that stays in front of the original window.

How it works

Although Internet Explorer and Mozilla based browsers use different methods, you don't need to test which browser you are currently running. Instead you can test for support for the showModalDialog method. The code looks like this:

if (window.showModalDialog)
{
    var dialogArguments = new Object();
    var _R = window.showModalDialog("popup.html", dialogArguments, ...
    ...    
}  
else //NS   

{  
    ...
    window.open("popup.html", ID, "modal,toolbar=false...
    winHandle.focus();
}

The code

To see an example, you can download the source files and double-click the default.html. The example shows you how to create a modal popup Window, as well as how to pass back popup Window textbox value to the parent Window.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here