JavaScript: Popup windows closes immediately -
I am trying to close all open pop-ups using javascript. I tried the following code but it does not work.
This is my code to open a pop-up window.
var childWindow = new array (); Function Popup Center (page URL, Title, W, H) {var left = (screen.width / 2) - (w / 2); Var top = (screen. High / 2) - (H / 2); Var targetWin = window.open (pageURL, title, 'toolbar = no, location = no, directories = no, status = no, menubar = no, scrollbars = yes, resizable = no, copyhistory = no, width =' + w + ', Height =' + H + ', top =' + up + ', left =' + left); ChildWindow [childWindow.length] = targetWin; If (window.focus) {targetWin.focus ()} return false; }
And to close all this open pop-up window is my code.
closeChildWindow () {if (childWindow.length ! = 0) {for (var i = 0; i & lt; childWindow.length; i ++) {childwind [i] .close (); }}}
I call the 'closechildWindow ()' function at the body's on-call event of the page. But when I try to open a pop-up window it is closed immediately, so the pop-up window does not open completely.
What's the problem with my code?
Thanks in advance.
Pop-ups should be started by user clicks I'm assuming that this is a problem for you Not because you are seeing a popup, if for just a second this means that the browser is not blocking it.
However, if you are doing this on the click of a link, then onunload
event will fire ... even if the page itself does not unload ! I was in the form of a big problem while working on this particular ambitious project.
What you may have to do is add an "unload" flag, which is set when a popup is opened and a clear code is set to a setTimeout
. Then, your on-the-fly
event can only check that flag and can not do anything if it is set.
Comments
Post a Comment