I want to open a popup window and disable the parent window. Below is the code that I am using;
function popup() { popupWindow = window.open('child_page.html','name','width=200,height=200'); popupWindow.focus(); }
For some reason, the parent window does not get disabled. Do I need some additional code OR what is the case?
Again, I am looking for something similar to what we get when we use showModalDialog()..i.e. it does not allow to select parent window at all..Only thing is I want to get the same thing done using window.open
Also please suggest the code which will be cross-browser compatible..
Set a flag once child window is open and unset it once its closed. In ShowPopup use event. preventdefault() if child window is open!
The syntax to open a popup is: window. open(url, name, params) : url.
var popupWindow=null; function popup() { popupWindow = window.open('child_page.html','name','width=200,height=200'); } function parent_disable() { if(popupWindow && !popupWindow.closed) popupWindow.focus(); }
and then declare these functions in the body tag of parent window
<body onFocus="parent_disable();" onclick="parent_disable();">
As you requested here is the complete html code of the parent window
<html> <head> <script type="text/javascript"> var popupWindow=null; function child_open() { popupWindow =window.open('new.jsp',"_blank","directories=no, status=no, menubar=no, scrollbars=yes, resizable=no,width=600, height=280,top=200,left=200"); } function parent_disable() { if(popupWindow && !popupWindow.closed) popupWindow.focus(); } </script> </head> <body onFocus="parent_disable();" onclick="parent_disable();"> <a href="javascript:child_open()">Click me</a> </body> </html>
Content of new.jsp below
<html> <body> I am child </body> </html>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With