View Full Version : Pop-up onBlur - close?
Eternity Angel
10-26-2002, 02:50 PM
I added an onblur="window.close();" to the body of my pop-up, and EXPECTED it to close if I switched to another window, yet, it did not.
Is there a certain way to do this? I HAVE seen a site with it, but of course, I don't remember the URL.
Any help is ppreciated :)
piniyini
10-26-2002, 03:00 PM
onblur="javascript:this.window.close();"
Eternity Angel
10-26-2002, 03:03 PM
That, to ME, is the same thing as just window.close();
I DID try it, and, of course, it didn't work.
Any other ideas?
mordred
10-26-2002, 04:15 PM
I just build a simple test case implementing the code you use. With IE5.5 and Moz1.0 I did not notice any problem, the popup window closed automatically whenever I focused on another window.
So I deduct there must be something else interfering with your script. Are there any other scripts that do sth. in your popup window (i.e. which maybe also try to set the onblur eventhandler)? It would be also good to know in which browser, version, platform you have this problem. The latest IE security update package stopped some javascript code from executing, though I don't know if that has anything to do with your problem.
Have you also tried the obvious (don't beat me, but I've forgotton a thousand times to reload a page/erase it from the cache to actually see code work ;))?
Eternity Angel
10-26-2002, 10:11 PM
Okay!
The pop-up looks like this:
<title>Viewing: A-01.jpg</title>
<body onblur="window.close();" onclick="window.close();">
<table height="100%" width="100%">
<tr>
<td align="middle" valign="middle">
<div width="100%" align="center" valign="middle">
<img name="image" src="pics/A-01.jpg">
<p>
<a href="#" onclick="window.close();return false;">Close</a>
</div>
</td>
</tr>
</table>
</body>
If it means ANYTHING, I am writting that pop-up with a function, and it's not a static HTML file:
function popup(a,b,c)
{
var opened = window.open("","","width=100,height=100,scrollbars=yes,left=0,top=0,resizable=yes");
opened.moveTo(0,0);
opened.resizeTo(screen.availWidth,screen.availHeight);
opened.focus();
opened.document.write('<title>Viewing: '+a+'-'+b+'.jpg</title>\n\n<body onblur="window.close();" onclick="window.close();">\n\n<table height="100%" width="100%">\n <tr>\n <td align="middle" valign="middle">\n <div width="100%" align="center" valign="middle">\n <img name="image" src="pics/'+a+'-'+b+'.jpg">\n <p>\n <a href="#" onclick="window.close();return false;">Close</a>\n </div>\n </td>\n </tr>\n</table>\n\n</body>');
if (c == 'yes') {
random = opened.image.height;
opened.image.height = (random*2);
}
}
I seriously do not know WHY it wouldn't work, because to my knowledge, the code is pretty straight-forward.
joh6nn
10-26-2002, 11:30 PM
so, question:
you're assigning most of the new window's methods as javascript properties. why are you assigning onblur as an html attribute? ( that's just curiosity )
have you tried assigning it as javascript property?
Eternity Angel
10-26-2002, 11:40 PM
What am I doing....? I didn't understand what you just said :-\
joh6nn
10-26-2002, 11:56 PM
function popup(a,b,c)
{
var opened = window.open("",""," width=100,height=100,scrollbars=yes,left=0,top=0,r
esizable=yes");
opened.moveTo(0,0);
opened.resizeTo(screen.availWidth,screen.availHeight);
opened.focus();
opened.document.write('<title>Viewing: '+a+'-'+b+'.jpg</title>\n\n<body onblur="window.close();" onclick="window.close();">\n\n<table height="100%" width="100%">\n <tr>\n <td align="middle" valign="middle">\n <div width="100%" align="center" valign="middle">\n <img name="image" src="pics/'+a+'-'+b+'.jpg">\n <p>\n <a href="#" onclick="window.close();return false;">Close</a>\n </div>\n </td>\n </tr>\n</table>\n\n</body>');
if (c == 'yes') {
random = opened.image.height;
opened.image.height = (random*2);
}
}
why do you have <body onblur="window.close()">, instead of opened.oblur = opened.close; ?
i'm not sure that changing it will fix anything, it just seems odd to me to have used the "opened" object to set all of these window properties, and then to suddenly switch to using HTML to set one property.
also, i notice that when you write the new document, you never include the opening "<html>" tag, and neither do you use the closing "</html>" tag. why?
and, which browsers are you testing this in?
chrismiceli
10-27-2002, 12:04 AM
Originally posted by John6nn
opened.oblur = opened.close
i think he ment opened.onblur = opened.close
Eternity Angel
10-27-2002, 12:05 AM
Because, I THOUGHT I had to have it in the HTML document I was making with the .write(); command...
I NEVER use the <html> tag - IE6 works fine without it, and it's not for a WEBSITE, it's for just my computer, so I don't need to be perfect.
glenngv
10-28-2002, 01:43 AM
your tags are incomplete to inform the browser that it is an HTML encoded page.
opened.document.write('<html><head><title>...</title></head><body onblur="window.close();">...</body></html>');
Eternity Angel
10-28-2002, 02:06 AM
Lmao, this is all helpless...
I have done everyone of these examples, and nothing works - THEREFORE, I will just abandon the idea of making my pop-up image viewer thingy disappear.
Thank you all for trying to help me anyways :-)
glenngv
10-28-2002, 02:27 AM
dont give up :)
can you post the modified code?
Eternity Angel
10-28-2002, 02:34 AM
Okay... Here's the ENTIRE page, minus the actual images, of course.
Quiet Storm
10-28-2002, 02:50 AM
Try this:
<BODY onBlur="javascript:top.close();">
Eternity Angel
10-28-2002, 02:58 AM
It's not the format that is the problem, I don't believe - I put as a temporary thing,
onblur="alert('This is functioning');"
and it NEVER alerting anything...
BTW - I ERASED the onblur="" in function in the previously attached file. I forgot to re-add what I had, which was just onblur="window.close();"
glenngv
10-28-2002, 05:09 AM
in the file you attached, you had onclick not onblur, maybe you put it for testing other event. Put back the onblur event. Then put this after opened.document.write() statement:
opened.document.close();
this will do the trick! :)
Eternity Angel
10-28-2002, 05:25 AM
I had the onblur, AND onclick actually, and I gave up on the document, then just left the onclick, so that wherever you clicked, the window would close.
Anyways, IT WORKS NOW! I know you're supposed to document.close() open windows, but I guess I just forgot :-\
Thank you very much, everyone, and sorry for making a stupid mistake that I shouldn't have.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.