Tuesday, March 07, 2006

Javascript: showModal(less)Dialog

In Javascript, if you need to open new window using window.showModalDialog or window.showModelessDialog and then submit form inside the new window, then the form will be submitted to new window, which is usually not the way that we want it to be. There's one workaround that is easy to implement. Just put <base target=_self> inside <head> tag.

What is the difference between window.showModalDialog and window.showModelessDialog? From how Javascript call this two function, when window.showModalDialog is called, the code will stop there and wait until the new window is closed, but for window.showModelessDialog, the code will keep running and don't wait until new window is closed. So if your parent window is supposed to wait until result from new window returns, then use window.showModalDialog. Otherwise, If you don't care about the result or the result is not needed inside the calling method, then use window.showModelessDialog.