-
hello all
trying to do something simply but keep failing to get it right, spawning a window with :
function NewWindow1() {
act = window.open("act_pre.htm", "act");
}
this works fine, then trying to close it from the original window with :
function closewindow()
act.close();
}
this does'nt work, i know the script is being called cos if i just put close() the origin window closes fine. Can anyone see where i am going wrong, naming the spawned window or calling its name when trying to close it.
any help appreciated, thanks!
gar
-
If my memory serves me right, I believe it's only 'window.close()', not 'act.close'. Try:
Code:
window.close('act')
Although I'm not sure if it will work well. 'window.close()' usually does the trick for me.
Hope this helped. :)
-
also, if the code you're running to close the window is INSIDE the window itself, you can use:That works very nicely. It doesn't even pop up those annoying messages in I.E saying "are you SURE you want to close the window?". All in all, it's a good function.
-
>also, if the code you're running to close the window is >INSIDE the window itself, you can use:
>self.close()
its not so i can't
>window.close('act')
nope first thing i thought of! if only it was that easy!
window.close()
close()
result in the same thing in fact. thanks for the help anyway!
Garrett
-
Hi Garrett,
If you have spawned a new popup window from your main page using javascript and want to close it from your main page, you can do this using a simple text link.
<a href="javascript: act.close();">CLOSE WIN</a>
Good luck
-
as i already said above the closing button is not in the same winow as the opening button this is why the problem arises.
thanks for you help
garrett
-
Garett,
As you've written your code, act is a local variable. That is, it's created by NewWindow1() and then is destroyed as soon as the function ends. What you need to do is declare the variable global:
Code:
var act = null;
function NewWindow1() {
act = window.open("act_pre.htm", "act");
}
function closewindow() {
if (act) act.close();
}
That should work. Let me know if you still have trouble!
-
I have popups to show enlarged pictures on my wifes art site. I load the following into each new popup
<body bgcolor="#000000" onBlur="window.close()">. In addition I plan to also put a link on the cosmetic only "close window" text to close( all thats needed is <a href="Javascript:window.close ()">) as I have discovered the onblur function doesn't seem to work in NS6 and Opera.
This then closes the window whenever a mouseclick occurs on either the popup or the original page.
No guarantees as I have'nt a clue about programming. This info was gleaned from help from others but it seems to work for me.