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!

onblur=self.close question

Status
Not open for further replies.

robert89

Technical User
Nov 19, 2003
125
CA
Hi there,
Trying to teach myself some js. Have a script that launches a popup when the parent loads. I have used onblur='self.focus();' in the function that writes the new window. While the onblur writes itself into the popups body tag as instructed, it doesn't work. Anyone have any idea how I can get this to work. The function is below:

<SCRIPT LANGUAGE="JavaScript">
function openindex()
{
var OpenWindow=window.open("", "newwin", "height=300,width=300");
OpenWindow.document.write("<html>")
OpenWindow.document.write("<title>New Window</title>")
OpenWindow.document.write("<body onblur='self.close();'>")
OpenWindow.document.write("<div align='center'>")
OpenWindow.document.write("<h1>New Window</h1>")
OpenWindow.document.write("<p>This will open<BR> in the main window</a></p>")
OpenWindow.document.write("<p><hr width='60%'></p>")
OpenWindow.document.write("<p><a href='' onclick='self.close()'> This closes the window</a></p>")
OpenWindow.document.write("</div>")
OpenWindow.document.write("</body>")
OpenWindow.document.write("</html>")
}
</SCRIPT>
 
What is popup supposed to do? Be always in front or get closed if user clicks in opener window? (close vs focus thing).

------
[small]select stuff(stuff(replicate('<P> <B> ', 14), 109, 0, '<.'), 112, 0, '/')[/small]
[banghead]
 
Want it to always be on top unless the visitor specifically close it. There are a number of links on the opener window and the folks I am doing this for, want the items to open in the popup and for the popup to stay in focus.
 
Then you need to replace the "self.close" with a "self.focus".

The post title indicated you wanted to close the window, the text in your post indicated you wanted it to be focussed, but the code you gave showed you wanted it closed. Confusing? Yes!

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hi BillyRayPreachersSon,
You're absolutely right. How sloppy can I get. The post does say self.close.

I want to open content in a popup i.e. word doc, have the popup stay in focus unless closed. If it's open, I want subsequent links to open in the same popup i.e. ppt file.

I thought if I created a window using document.write I could have the instruction onblur="self.focus();" written into the body tag. The script I have above creates a window, places everything where I've asked. While the onclick='self.close()' works, the onblur='self.focus();' does not.

My question was a matter of wondering if anyone might know why this was the case and/or offer a work around.

Trust it's all a bit clearer this time. Sorry for the sloppy first post.

 
Hi BillyRayPreachersSon,
I used .doc and .ppt as examples, but I have run the above script just to create the html popup. It creates the html popup fine, but the onblur="self.focus();" (written to the body tag) does not work while the onclick="self.close();" works fine.

I was wondering why this would be.

Thanks,
Bob
 
No idea... but really, unless you are going to be loading only HTML files into the window, you may as well stop looking for a solution to this now.

Of course, the above statement assumes you want a cross-browser solution. If you're on an intranet, and your target browser is IE only, you could investigate whether the showModalDialog function is too restrictive for your needs.

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks BillyRay,
The project that these questions are related to will actually be limited to a pc with IE only (Unfortunately!). So thanks for all your responses. I will continue to look into a solution.

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top