View Full Version : How to close a popup window
oldsoul1219
10-08-2002, 06:50 PM
My client wants to be able to place the cursor on a link and preview the page that will be linked to if the link is clicked. I am using mouseover to popup a window and want to close the window on mouseout. I get a confirm message asking if I want to close the (main) window and the popup stays. Here's my javascript:
function openWindow(url)
{
popupWin = window.open(url,'remote','scrollbars,resizable,width=700,height=500,top=150,left=120')
}
function closeWindow(url)
{
window.close(url, 'remote')
}
and here's the site (popup occurs only on "Abuse" -- mouseover it on the sidebar to see the popup, mouseout to see the confirm message):
http://www.bcdenterprises.net/cw/index3.htm
I think this must be simple but I can't quite get it (I've tried several things, the abbove is the latest). Can anyone help?
adios
10-08-2002, 06:57 PM
var popupWin = null;
function openWindow(url)
{
popupWin = window.open(url,'remote','scrollbars,resizable,width=700,height=500,top=150,left=20')
}
function closeWindow(url)
{
if (popupWin && !popupWin.closed) popupWin.close();
}
Note: this forum is completely nuts in editing window.open() script - it won't let it on one line most of the time & inserts unwanted spaces. :mad:
oldsoul1219
10-08-2002, 07:22 PM
Thank you so much. I see now what's going on, that I needed to define/identify the window. Again, thank you.
^KoalaBear^
10-09-2002, 05:20 AM
I have been trying to follow this interesting thread and thought I'd try to amend it and code it on a test page I loaded to my site... but as you'll see, it doesnt work! LOL... Now that shouldn't come to any shock to me... as I prolly average-score about 10/100 on copy and paste and amendments!
I wonder if one of you might please check my test page out and show me the error of my ways, please! :o
Here it is HERE (http://home.graffiti.net/kbs_great_aussie_sites/howto/how-to.html)
The link.html is located HERE (http://home.graffiti.net/kbs_great_aussie_sites/howto/link.html)
Cheers
KB...
adios
10-09-2002, 05:48 AM
Oops, problems galore. First: forgot your <script></script> container. Any time your JS shows up - on the page - that's usually the deal (or a typo). Next: keep in mind, since you're calling this from a mouseover, and closing the window from a mouseout, if the window opens over the link, a mouseout will fire immediately since you're no longer over the link. You need to control where the window opens.
<p><font color="#CC0000"><font size=+1>Sample Link: </font></font><b><a href="http://home.graffiti.net/kbs_great_aussie_sites/howto/link.html" onMouseOver="openWindow('link.html')" onMouseOut="closeWindow('popupWin')">LINK</a></b></center>
<script type="text/javascript">
var popupWin = null;
function openWindow(url)
{
popupWin = window. open(url,'remote','scrollbars,resizable,width=300,height=200,top=20,left=20');
if (popupWin && !popupWin.closed) popupWin.focus();
}
function closeWindow(sHandle)
{
if (window[sHandle] && !window[sHandle].closed) window[sHandle].close();
}
</script>
Notice: you don't need any url to close the window, just a string version of the variable name you opened it with; plug this into the (current) window object to find the pop-up window object, your 'handle' on it.
^KoalaBear^
10-09-2002, 06:07 AM
LOL What took ya so long to reply?? (Joking Mate!)
Well I pasted your script over what I thought was the relevant code of mine and uploaded it again as how-to2.html. I think I see what you've said makes sense, but alas I am still not getting a window to popup on hover...
See HERE (http://home.graffiti.net/kbs_great_aussie_sites/howto/how-to2.html)
:confused:
adios
10-09-2002, 06:18 AM
Put this:
'scrollbars,resizable,width=300,height=200,top=20,left=20'
...all on one line. As I mentioned earlier today, the editor screws up window.open code here consistently. Remove the space after window.[here]open for good measure. You can also get the mouse co-ordinates and open the pop-up adjacent to the cursor - although, that suggests you might want to scrap the whole thing and use one of these:
http://www.dynamicdrive.com/dynamicindex5/index.html
^KoalaBear^
10-09-2002, 06:28 AM
GREAT... I see where the problem is... I have had that space/line problem before and hope I might look for those kinds of errors as I get more experienced... if in fact that happens to 60 yr old newbies! LOL
Your amendment is HERE (http://home.graffiti.net/kbs_great_aussie_sites/howto/how-to3.html)
I sincerely appreciate your time and patience, my friend :thumbsup:
Cheers!
KB...
oldsoul1219
10-09-2002, 05:51 PM
Adios beat me to the reply and probably did a better job than I would have (or quicker at least)! I have found that cutting and pasting code is prone to errors -- spaces get inserted and "things" get lost or convoluted -- so I end up typing in the code.
Also, you probably noticed that popping up an html page is slow, since the page is built in the popup window -- after doing the work, my client decided she didn't want it. I suggested just a little text in a popup but she didn't want that either. I guess that's inherent in the business , huh? At least ya learn things.
Once again, thank you Adios, you've been very informative.
^KoalaBear^
10-09-2002, 11:05 PM
Thanks and no worries, Mate! Adios did good....again!
Cheers
KB...
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.