Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
90
rated 0 times [  97] [ 7]  / answers: 1 / hits: 17487  / 14 Years ago, fri, august 20, 2010, 12:00:00

Can any one tell me the difference between these functions?


More From » javascript

 Answers
28

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.


[#95865] Monday, August 16, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
estefanib

Total Points: 508
Total Questions: 104
Total Answers: 83

Location: Lebanon
Member since Sun, Aug 2, 2020
4 Years ago
;