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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

weird javascript unload problem

Status
Not open for further replies.

pigsie

Programmer
Joined
Dec 19, 2000
Messages
307
Location
GB
Hi

I have the following code which launches a pop up using the onunload event. THing is if I simply want an alert to display it works fine but if I want to create a pop up the pop up never opens.

So this works:

<script language="JavaScript">
function closing(){
alert('hello');
}

window.onunload = closing;
</script>

But this does not:

<script language="JavaScript">
function closing(){
window.open('}

window.onunload = closing;
</script>
 
I don't know... it seems work for me.
 
What are the REAL values you're using for your URL and window name? The window.open(...) command, I know, balks when there are spaces in the window name. 'survey' should work, but 'my survey' is better converted to 'my_survey' (for example).

Otherwise... not sure! If the above doesn't help, I would try my mystery solution for problems I don't understand.

Change:

window.open('
to

setTimeout("window.open(',0);

Good luck!

--Dave
 
Here is simple testing page.
[tt]
<html>
<head>
<script language="JavaScript">
//So this works:
function closing(){
alert('hello');
}
//But this does not, so we're told:
function closing_2(){
window.open('}

window.onunload=function() {
closing();
closing_2();
}
</script>
<body>
<p>[1] Testing onunload with popup.</p>
<p>Click upper right button to close this page.</p>
<p>[2] Further test to unload by redirection with button.</p>
<button onclick="window.location.href=' to yahoo</button>
</body>
</html>
[/tt]
 
guys thanks for the suggestions. I forgot to add that it works for me but not on a couple of my colleague's pcs. I've triple checked that they do not have a pop up blocker installed or an old version of the page. I will try it on their pcs tommorow and let you know how it goes. THanks again
 
Maybe the popup is already open but it is hiddend behind other windows. On the popup, try this:

<body onload="self.focus()">
 
Thanks guys. I found out the problem - turns out that most people do not realise it but they usually have more than 1 pop up blocker - one machine had one in the google toolbar, one in a plugin and one default built in browser pop-up blocker. After disabling all 3 the pop up code worked as it should.
Sorry for the read Herring.

Thanks

 
They should set the browser to allow popup from work site when popup is turned on.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top