freespirit020199
asked on
Auto Close a popup window containing an image only (no html).
I have a new smaller window pop up when someone clicks on a thumbnail image on my page. I do this by using the following code:
<a target="_self" onclick="window.open('dire ctory/larg erimage1.j pg','windo w1','scrol lbars=yes, width=200, height=200 ')"
href="samepage.htm"><img src="directory/thumbnailim age1.jpg" WIDTH="60" HEIGHT="60">
I would like to know how to get this window to self close after a specified time so that they do not end up having a number of windows open after clicking on the various thumnails present.
I found answers saying to place Java Script in the new window telling it to self close after X seconds. However since my new window points only to an image file (jpg or gif) there is no html in the new window containing the <head> tag nor a <body> tag, just a directory/image.jpg. Please help me I am not html savvy but trying my best to understand what I need to to get this page done soon. Help.
<a target="_self" onclick="window.open('dire
href="samepage.htm"><img src="directory/thumbnailim
I would like to know how to get this window to self close after a specified time so that they do not end up having a number of windows open after clicking on the various thumnails present.
I found answers saying to place Java Script in the new window telling it to self close after X seconds. However since my new window points only to an image file (jpg or gif) there is no html in the new window containing the <head> tag nor a <body> tag, just a directory/image.jpg. Please help me I am not html savvy but trying my best to understand what I need to to get this page done soon. Help.
Try this:
<HTML>
<HEAD>
<SCRIPT language='javascript'>
function closewin( windowname )
{
var winh = window.open( "", windowname ); // get handle to window
if ( winh && !winh.closed )
{
winh.close();
}
}
function openwin( theURL )
{
var windowname = (""+Math.random()).substri ng(1);
var winh = window.open( theURL, windowname, 'scrollbars=yes,width=200, height=200 ');
setTimeout( 'closewin("'+windowname+'" );', 30000 );
}
</script>
</head>
<BODY>
<a target="_self" onClick="openwin('director y/largerim age1.jpg') ;return(fa lse);" href="samepage.htm"><img src="directory/thumbnailim age1.jpg" WIDTH="60" HEIGHT="60" border="0"></a>
</body>
</html>
<HTML>
<HEAD>
<SCRIPT language='javascript'>
function closewin( windowname )
{
var winh = window.open( "", windowname ); // get handle to window
if ( winh && !winh.closed )
{
winh.close();
}
}
function openwin( theURL )
{
var windowname = (""+Math.random()).substri
var winh = window.open( theURL, windowname, 'scrollbars=yes,width=200,
setTimeout( 'closewin("'+windowname+'"
}
</script>
</head>
<BODY>
<a target="_self" onClick="openwin('director
</body>
</html>
... adjust the milliseconds in the setTimeout to your liking.
one typo -- in the openwin() function change: substring(1); to: substring(2);
I think there's an easier way...
This should work, put it in your body statement, ie:
<body onLoad="setTimeout(window. close, 10000)">
The number there is milliseconds I believe. Should work...did for me at least...
Kevin
This should work, put it in your body statement, ie:
<body onLoad="setTimeout(window.
The number there is milliseconds I believe. Should work...did for me at least...
Kevin
Yes, but that will not work with the current code because the window is not opening an HTML page, but a .jpg file, so there is no BODY tag (or any other tag for that matter).
any thoughts, freespirit?
ASKER
Adjusted points from 50 to 60
ASKER
Thanks everyone...I apologize for the delay but I was unable to come back to this project until now.
knightEknight, your script worked beautifully. You were correct about the fact that the pop-up window had no body codes as it was a simple image file, which is why the other answer would not work. I intend to give you the points. One last clarification however: the size of the new pop-up windows are determined in the script placed in the <head> tag. Firstly will this work with multiple thumbnails on a single page, for multiple pop-up wndows per page? Also the new window often needs to be different sizes depending on the larger image. In my previous code, I was able to determine that by:
onclick="window.open('dire ctory/larg erimage1.j pg','windo w1','scrol lbars=yes, width=200, height=200 ')"
for each window.open command. Your way is great except for the fact that the new window size is fixed for every thumbnail. How can I get around that?
knightEknight, your script worked beautifully. You were correct about the fact that the pop-up window had no body codes as it was a simple image file, which is why the other answer would not work. I intend to give you the points. One last clarification however: the size of the new pop-up windows are determined in the script placed in the <head> tag. Firstly will this work with multiple thumbnails on a single page, for multiple pop-up wndows per page? Also the new window often needs to be different sizes depending on the larger image. In my previous code, I was able to determine that by:
onclick="window.open('dire
for each window.open command. Your way is great except for the fact that the new window size is fixed for every thumbnail. How can I get around that?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry, my typing is not the best today (it's Monday)
"elagorate" should be "elaborate", as one example.
"elagorate" should be "elaborate", as one example.
ASKER
As you requested, the page with my problem code is at:
http://www.newworldrealtors.com/showcase/showcaseindex.htm
I have just replaced the previous code with the one above and it seems to be working fine. I have not uploaded it as yet though so you would see your code in action probably within a few days.
I realize that the code you so kindly gave me opens each window in a separate window. This is fine since they each close after the seconds set. But for future's sake, is there a way to fine tune it so that each time someone clicks a separate thumbnail it opens into the SAME window? Is this asking too much? If so, then no prob... as it works fine as is.
Thanks again. Will be back to check or accept the answers as soon as I get this uploaded.
http://www.newworldrealtors.com/showcase/showcaseindex.htm
I have just replaced the previous code with the one above and it seems to be working fine. I have not uploaded it as yet though so you would see your code in action probably within a few days.
I realize that the code you so kindly gave me opens each window in a separate window. This is fine since they each close after the seconds set. But for future's sake, is there a way to fine tune it so that each time someone clicks a separate thumbnail it opens into the SAME window? Is this asking too much? If so, then no prob... as it works fine as is.
Thanks again. Will be back to check or accept the answers as soon as I get this uploaded.
ASKER
knightEknight:
P.S. Is there a way to contact you regarding your services and fees, if so required in the future?
P.S. Is there a way to contact you regarding your services and fees, if so required in the future?
How about if we close the popup as soon as another one is opened? Try this:
function closewin( windowname ) // the only change here is to rename winh to winh2
{
var winh2 = window.open( "", windowname ); // get handle to window
if ( winh2 && !winh2.closed )
{
winh2.close();
}
}
var winh=null; // move this declaration outside the function to make it global.
function openwin( theURL, w, h )
{
if ( winh && !winh.closed ) // if a previous window is still open, then close it immediately
winh.close();
var windowname = (""+Math.random()).substri ng(2);
winh = window.open( theURL, windowname, 'scrollbars=yes,width='+w+ ',height=' +h);
setTimeout( 'closewin("'+windowname+'" );', 30000 );
}
If you want my email address, post another question for 0 points. I'll lock it, you accept it, and then I'll add my email address as a comment. Thanks!
function closewin( windowname ) // the only change here is to rename winh to winh2
{
var winh2 = window.open( "", windowname ); // get handle to window
if ( winh2 && !winh2.closed )
{
winh2.close();
}
}
var winh=null; // move this declaration outside the function to make it global.
function openwin( theURL, w, h )
{
if ( winh && !winh.closed ) // if a previous window is still open, then close it immediately
winh.close();
var windowname = (""+Math.random()).substri
winh = window.open( theURL, windowname, 'scrollbars=yes,width='+w+
setTimeout( 'closewin("'+windowname+'"
}
If you want my email address, post another question for 0 points. I'll lock it, you accept it, and then I'll add my email address as a comment. Thanks!
ASKER
Thanks a million knightEknight
I used your solution at:
http://www.newworldrealtors.com/showcase/showcaseindex.htm
It does what you say and works fine. There is something that happens after the 30 seconds is up where briefly a blank browser page flashes before disappearing but I am not sure what that is about. But it does the job fine for me. This is much better than what i had tried to do before.
Thank you. I will post that question re the email so look out for it.
I used your solution at:
http://www.newworldrealtors.com/showcase/showcaseindex.htm
It does what you say and works fine. There is something that happens after the 30 seconds is up where briefly a blank browser page flashes before disappearing but I am not sure what that is about. But it does the job fine for me. This is much better than what i had tried to do before.
Thank you. I will post that question re the email so look out for it.
<SCRIPT language='javascript'>
var winh = window.open("","window1");
setTimeout( "if ( winh && !winh.closed ){winh.close();}", 30000 ); // close the window after 30 seconds
</script>