...

View Full Version : Popup code



djfenom
06-12-2003, 01:12 PM
Hi all, I'm currently using this bit of code for image popups, basically so I don't have to create an individual page for each one. It works fine, however it keeps open each popup when you open another one. Is there anyway anyone could tweak the code so that when a new popup opens, it closes the previous one first. For example, when I click a link to get a popup, this currently stays open unless you physically close the window, what I need is when you click on another link for a different popup, the previous one is closed and over-ridden by the current one.

function popimage(imagesrc,winwidth,winheight,winsb){
var look='width='+winwidth+',height='+winheight+',scrollbars='+winsb+' ,'
popwin=window.open("","",look)
popwin.document.open()
popwin.document.write('<title>Popup</title><body topmargin=0 leftmargin=0 marginwidth=0 marginheight=0><img src="'+imagesrc+'"></body>')
popwin.document.close()
}

Thanks in advance

Chris

ez4ne12c
06-12-2003, 01:34 PM
I think you can use something like
opener.close();

ez

Choopernickel
06-12-2003, 01:47 PM
Really, it's as simple as naming your window.

Use window.open("", "windowname", look);

This window will be reused if it is available, and created if it is not.

djfenom
06-12-2003, 02:53 PM
Thanks guys.

My link currently looks like this:

<a href="#" onClick="popimage('images/contracts-pop-image1.jpg',550,367,0);return false">

How would I implement said change into this??

Thanks

Chris

Choopernickel
06-12-2003, 03:23 PM
popwin=window.open('','winName',look);

would go inside your function where it now reads

popwin=window.open('','',look);

djfenom
06-12-2003, 03:33 PM
Ahh, I get it, thanks for that, it does work now, however there are a couple of problems.

The first is that the popup does get replaced, but it stays at the bottom of the screen minimized and doesn't pop back up?

The second is some of the popup images are different sizes and I would like it to resize these rather than just overlay in the previous popup window.

Thanks.

Chris

Choopernickel
06-12-2003, 04:05 PM
Gotcha.

Add this before you open popwin:


if (popwin) {
try{
popwin.close();
} catch(e) {
ignore="this error";
}
}

That might work. If not, outside your function declare

var popwin;
and that will help.

What's your target audience? (Browser type, version, etc)

arnyinc
06-12-2003, 04:09 PM
This covers everything. popwin.resize takes care of resizing. window.focus makes it show up on top every time.


<html>
<head>
<script>
function popimage(imagesrc,winwidth,winheight,winsb){
var look='width='+winwidth+',height='+winheight+',scrollbars='+winsb+' ,';
popwin=window.open("","mypop",look);
popwin.document.open();
popwin.resizeTo(winwidth, winheight);
popwin.document.write('<title>Popup</title><body onload="window.focus()" topmargin=0 leftmargin=0 marginwidth=0 marginheight=0><img src="'+imagesrc+'"></body>');
popwin.document.close();
}
</script>
</head>
<body>



<a href="#" onClick="popimage('map.gif',425,511,0);return false">1</a>
<a href="#" onClick="popimage('mapquest.gif',400,400,0);return false">2</a>
<a href="#" onClick="popimage('mapvr1.gif',390,390,0);return false">3</a>
<a href="#" onClick="popimage('bo030611.gif',600,197,0);return false">4</a>

</body>
</html>

djfenom
06-12-2003, 04:15 PM
That's the baby, works like a treat, thanks Choopernickel and arnyinc, very much appreciated.


Chris



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum