We know that to open a pop-up we use window.open( [sURL] [, sName] [, sFeatures] [, bReplace]).
But, what if we want to open it as a modal window? We can use window.showModalDialog(sURL [, vArguments] [, sFeatures]).
But this approach has certain disadvantages, your client side script does not always behave the way it should otherwise.
So the best possible approach to open a modal pop-up window is,
From your page, open a normal popup as
window.open(‘/_layouts/OpenOpUp.aspx?Mode=New’, ‘pop1′,‘left=80, top=50, center=yes, height=480, width=450,status= no, resizable= no, scrollbars=yes, toolbar=no, location=no,menubar=no’);
Now, in the modal popup window(here, OpenOpUp.aspx) in the body tag write,
<body onblur=”self.focus()”>
Your job is done, now it will behave as a modal popup window as it will have focus on itself and you have to close the page to get back to the parent page (either through javascript or by clicking the cross button at top) and all your client side scripts will work just fine.
February 10, 2009 at 12:29 pm
thanks for sharing a useful article.
It saved me hell lot of time..
April 3, 2009 at 6:05 am
thanks for givin the way..
if my popup contains dropdown or some controls i m not able to select those coz of onblur event
April 3, 2009 at 10:22 am
Hi Kumar,
You are right, my objective as clearly stated in the post above was to let the user do anything on the parent page without closing the pop-up as the users were complaining that they often forgot to close the pop-up(or select value that falls on the parent page) and wanted a way to be forced to remember to close it.So my approach was perfect to cater to that requirement.
If you also want to work with parent windows(as you mentioned selecting and de-selecting dropdown list) then the best option would be showModalDialog.
As you know the approach to different problems is not always the same.