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!

closing window on losing focus 2

Status
Not open for further replies.

RobBroekhuis

Technical User
Oct 15, 2001
1,971
US
Hi all,
Newbie alert once again. I'm generating a popup window on the fly. The window generation works just fine. View source shows:

<html><head><style> body {background-color=#FFFFEE; font-family=&quot;Arial&quot;; font-size=16Px}</style>
<body onBlur=&quot;window.close()&quot;>
&nbsp;
<form onSubmit=&quot;window.close()&quot;><p align=center><input type=&quot;submit&quot; value=&quot;close&quot;></form>

The close button works - the popup window closes. However, the onBlur doesn't work - when I pull up the calling window again, the popup just moves into the background, without closing. I took the <body onBlur= > tag straight from the JavaScript reference pages. Why doesn't it work?


Rob
[flowerface]
 
If you want the window to close when focus is lost, why not just make it a modal window? That way the window won't close until the user purposely closes the window. And by the time focus would have been put back to the original page, the window would be gone anyway.

-kaht

banghead.gif
 
That's a good idea, and I may implement it that way. Still, I'm curious why it doesn't work as written now.
Using IE6 in Win2000, if that matters.


Rob
[flowerface]
 
Hey Kaht,
How do I pop up a modal window? The closest I could find in the window.open documentation is the &quot;dependent&quot; setting, which isn't quite the same.


Rob
[flowerface]
 
I'm not sure of the exact syntax. It's something along the lines of:

document.showModalDialog(not sure of the parameters)

A google search or even a search in this forum should probably give you the answer's you're searching for

-kaht

banghead.gif
 
I did find that - but according to the information I found, that only works for IE. I don't have Netscape here, so I can't test if that is still the case. DHTML workarounds exist, but are cumbersome. I wish my simple onBlur clause would just work...



Rob
[flowerface]
 
Could it be because you're missing the closing &lt;/head&gt; tag?

Adam
while(ignorance==true){perpetuate(violence,fear,hatred);life=life-1};
 
This works for me to close a window onBlur.
Code:
&lt;html&gt;&lt;head&gt;&lt;script&gt;
function bye() {

  self.opener=this;
  self.close();
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body onBlur = &quot;bye()&quot;&gt;
Test
&lt;/body&gt;
&lt;/html&gt;
As a bonus it doesn't display any warnings. You're right Adam!
Hope it helps

Glen
 
glenmac,
Thanks for posting your code! Can you explain the
self.opener=this
line? Unfortunately, the code doesn't seem to be working for me. This is what I have:
Code:
&lt;html&gt;&lt;head&gt;
&lt;script&gt;function bye() {self.opener=this; self.close(); } &lt;/script&gt;
&lt;/head&gt;&lt;body onBlur=&quot;bye()&quot;&gt;
Shown below is your post as it will appear in the forum
&lt;table width=100% bgcolor=0&gt;&lt;tr&gt;&lt;td align=center&gt;
&lt;button onClick=&quot;window.close()&quot;&gt;go back to edit&lt;/button&gt;
&lt;button onClick=&quot;opener.document.SubmitThread.submit(); window.close()&quot;&gt;submit&lt;/button&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/body&gt;
[code]
Unfortunately, the code seems to never fire (when I put onBlur=&quot;alert('help')&quot;, nothing happens either).  Does your code work for you in IE6?


[i][COLOR=blue]Rob[/color][/i]
[flowerface]
 
It works for me. Are you getting an error or something?

Adam
while(ignorance==true){perpetuate(violence,fear,hatred);life=life-1};
 
Curiouser and curiouser. But I'm getting closer, I think. The example above indeed works. As done the one I posted above: when I copied the page from &quot;view source&quot; into new document, it works fine. It just doesn't work within my application. I think I understand why: I create this page on the fly, by opening a blank window and writing to the window's document. I guess you can't write scripts to a document this way? On the other hand, the button onclick events work just fine. So I'm still confused.


Rob
[flowerface]
 
Ahhh, that's why. Try adding document.close() after you write the contents. The page doesn't know that it's ok to run script until you do that.

Adam
while(ignorance==true){perpetuate(violence,fear,hatred);life=life-1};
 
Actually, I said that a little wrong. Until document.close() is used, the &lt;body&gt; tag doesn't know if more data is going to be written to it or not.


Your code would look something like this:
Code:
var win=window.open();
win.document.write(popupContent);
win.document.close();

Adam
while(ignorance==true){perpetuate(violence,fear,hatred);life=life-1};
 
On the nose! Thanks so much - this was starting to frustrate me to no end!
Pet peeve alert: in your tagline, why not remove the &quot;==true&quot;? :)

Rob
[flowerface]
 
how could you point out the ==true and not mention life--???

j/k :)

-kaht

banghead.gif
 
Actually, I used to have life-- but I was afraid some people wouldn't get it. Rob, I would hate to &quot;peeve&quot; anyone so I changed my sig just for you.

Adam
while(ignorance){perpetuate(violence,fear,hatred);life=life-1};
 
I'm glad you were able to get things working. The line is declaring the opener for the window is the window. Hmm, sounds confusing, it's a hack to stop the warning box about closing a window from apearing.

Glen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top