Page 1 of 1
how to close a popup when another is opened?
Posted: Tue Aug 04, 2009 1:23 pm
by garyed
I have a web page with a bunch of small jpg's that will enlarge in a popup window when clicked.
The problem I have is if one is opened & not closed & another of the small jpg's is clicked on then the popup
will not show on the screen. It will just drop to the bottom menu bar. I really only want one popup to show at a time so is there a way to
set the window.open or something similar so it will automatically close whatever else is opened or even just take its place?
Here is some of my code:
Code: Select all
// Function to open up pictures in a popup window, an example of how its used is below
// <img style="..." alt="..." src="s1carib.jpg" onclick="pictures('01carib.jpg')">
function pictures(jimage)
{
window.open (jimage,"The_Pics","menubar=no,statusbar=no,location=no,toolbars=no,scrollbars=yes,width=675,height=675,resizable=0,top=50,left=50");
}
Re: how to close a popup when another is opened?
Posted: Tue Aug 04, 2009 1:40 pm
by jackpf
If you have a title for your window, which you do ("The_Pics") then the window should only open once, and any further requests with that title will be opened in the same window.
Is that not the case?
Re: how to close a popup when another is opened?
Posted: Tue Aug 04, 2009 1:41 pm
by jackpf
Sick, that was my 666th post

Re: how to close a popup when another is opened?
Posted: Tue Aug 04, 2009 1:52 pm
by garyed
jackpf wrote:If you have a title for your window, which you do ("The_Pics") then the window should only open once, and any further requests with that title will be opened in the same window.
Is that not the case?
Well yes the window only opens once but it gets minimized down the bottom of the screen if its not closed before opening another window.
I hope its O.K. to post url here but its a lot easier to see what's happening when you click a picture with one already opened.
http://www.brokerbythesea.com/island_pics.html
Re: how to close a popup when another is opened?
Posted: Tue Aug 04, 2009 1:58 pm
by jackpf
Oh right, I see.
Well, I don't think you can really avoid that with window.open().
You could, however, close the window when they go back to the main page, and then open it again when they click on the next image. Just put this in the child window:
Code: Select all
<script>
window.onblur = function()
{
window.close();
}
</script>
Re: how to close a popup when another is opened?
Posted: Tue Aug 04, 2009 2:04 pm
by garyed
Thanks,
I'll try that out & see how it works.
Re: how to close a popup when another is opened?
Posted: Tue Aug 04, 2009 2:45 pm
by garyed
jackpf wrote:Oh right, I see.
Well, I don't think you can really avoid that with window.open().
You could, however, close the window when they go back to the main page, and then open it again when they click on the next image. Just put this in the child window:
Code: Select all
<script>
window.onblur = function()
{
window.close();
}
</script>
I'm not having much success.
I'm not sure where to exactly put that code & how to execute it.
Re: how to close a popup when another is opened?
Posted: Thu Aug 06, 2009 8:25 am
by jackpf
Okaaaay.....
Anyway, this is what I suggest:
Have a php page called img.php, or whatever.
Then, instead of linking to the image, link to img.php?img=the_image_to_display.jpg
And then in img.php:
Code: Select all
<?php
if(isset($_GET['img']))
{
$img = basename($_GET['img']);
echo '<script>
window.onblur = function()
{
window.close();
}
</script>
<img src="images_dir/'.$img.'" alt="'.$img.'" />';
}
else
{
echo 'No image defined';
}
?>
Something like that anyway.
Re: how to close a popup when another is opened?
Posted: Thu Aug 06, 2009 10:03 am
by pickle
You should be able to assign the new window to a variable, then focus() that variable:
Code: Select all
var fullWindow = window.open(...);
fullWindow.focus();
Re: how to close a popup when another is opened?
Posted: Thu Aug 06, 2009 10:24 am
by jackpf
Oh wow, I didn't know you could do that.