Anto Varghese
Anto Varghese

Reputation: 3241

Difference between window.showmodaldialog and window.open

Can any one tell me the difference between these functions?

Upvotes: 2

Views: 17654

Answers (3)

Pekka
Pekka

Reputation: 449415

window.open opens a new independent window. It works in most browsers in some way (although pop-up blockers often block them or require additional user confirmation). It is possible to access the document that opened the window using the window.opener property.

showModalDialog opens a dialog that is tied to the current page. It is impossible to do anything on the page until the dialog gets closed. (MSDN docs)

The most important distinction between the two is that showModalDialog halts the execution of the JavaScript until the dialog box is closed, and can return a return value (at least in Internet Explorer). In that, it works similar e.g. to the confirm() dialog. In contrast, window.open opens a window "asynchronously": script execution will continue immediately, even while the new window loads.

It is possible to access the parent document from the dialog with some property whose name I can't remember right now, but it is different from window.open.

One more thing to note is that in my experience, modal dialogs are awfully difficult to refresh, as they seem to be subject to different caching rules than normal pages. The F5 key won't work to refresh the page. One workaround is to use a random addition to the loaded URL every time (pagename.htm?random=1203402920)

In general, seeing as showModalDialog is a proprietary function and its functionality can't be easily ported to other browsers, it's usually best not to use it.

Upvotes: 14

MrEdmundo
MrEdmundo

Reputation: 5165

From MSDN

A modal dialog box retains the input focus while open

This means that while it's open the user cannot obtain focus on the Window it was opened from. Window.Open will create a new Window.

Upvotes: 2

Sam
Sam

Reputation: 1514

Showmodaldialog will do exactly as it says, show a modal dialog, ie a window that the user needs to close first before he can get back to the original window, window.open will just open a new window, but the user is free to ignore this and get back to the original window whenever he wants.

Upvotes: 1

Related Questions