Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add to this..?

Status
Not open for further replies.

idaryl

Technical User
Nov 10, 2001
156
US
Hello Alll,

I currently am using this href script to open windows containing pictures - saves a lot of unnecessary pages. (The unfortunate thing with this is that it leaves a lot of windows open if the user does'nt close them.....)

<a href=&quot;picture.jpg&quot;; onClick=&quot;window.open(this.href, 'popupwindow', 'width=400,height=300,scrollbars=0,resizable=0'); return false;&quot;>

anyway, is there a way to add an onBlur=&quot;window.self.close()&quot; that will close the window if the user clicks somewhere else?

I'm using this (href script) rather than a .js script as I don't want to intefere with other running scripts on the page.

idaryl
idface.gif
 
Well... not really... because you are opening a JPEG (rather than an HTML) file. Because you are opening the window in a popup you could get a handle to the window... but since you are doing this inline with the href, again this is not that straightforward.

Having said all that... your code implies to me that only 1 popup will be made... each link you click on will open the window in the same popup (because you use the same name for the window - popupwindow).

There is no reason not to use a javascript function to do this. It will not &quot;interfere&quot; with other scripts if you give the function a unique name.

You could close any child popups when you onunload the body of the main (parent) HTML page though. That would have the effect of tidying up. Or you could add the &quot;dependant&quot; option to the popup (so it closes when the main page closes etc).

Just some early morning ideas.

Jeff
 

idaryl,

Check out my code in an earlier thread. It shows how to close all popup windows opened from a main window, when that main window is closed: thread216-749413

Hope this helps,

Dan
 

Simon,

Your FAQ refers to something called document.activePopup.

I cannot find any reference to this on MSDN, and if I run the code you gave (in IE6), I keep getting told that document.activePopup.length is null or not an object.

Here's my test code incorporating your FAQ code:

Code:
<html>
<head>
<script type=&quot;text/javascript&quot;>
<!--
	function closeAll() { for(var x=0;x<document.activePopup.length;x++) document.activePopup[x].close(); }
//-->
</script>
</head>

<body>
<a href=&quot;javascript:var myWinHandle = window.open('', '', '');&quot;>open new</a>
<br>
<a href=&quot;javascript:closeAll();&quot;>close all</a>
</body>
</html>

Are you sure that document.activePopup exists?

Dan
 

Glad you pointed me to the FAQ section - Just posted mine there too - the more the merrier, I say!

faq216-4783

Dan
 
Dan,

Thanks for pointing that out - I've changed the faq now - that'll teach me to write faq's first thing in the morning.

Simon
 
I think it's acceptable practice to write FAQs first thing in the morning... it's the lack of caffiene that is the actual root of the problem.

I blame the small coffee mugs we have here at work *grin*

Jeff
 
Perhaps I should IV drip caffeine through the night and wake up, big eyed and bushy tailed!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top