Topic: Javascript problem |
|
---|---|
Author | Thread |
Bipolar (III) Inmate From: |
posted 05-25-2006 14:51
ok i have this code which opens a centralised new window with the home page then sets the browser to refresh after 5 seconds to the home page code: <script language="Javascript"> function Redirect() { window.location="home.htm"; } function NewWindow() { left=(700-screen.width)/2; top=(150-screen.height)/2; window.open("home.htm", "main", "resizable=1,HEIGHT=423,WIDTH=700,left=150,top=150,screenX=left,screenY=top"); Refresh=setTimeout("Redirect()",5000); } function Stopit() { clearTimeout(Refresh); } </script>
code: onload="javascript: window.opener.Stopit()"
|
Maniac (V) Mad Scientist From: 100101010011 <-- right about here |
posted 05-26-2006 18:00
Nothing pops right out except I'd take out the "javascript: " you shouldn't need it on event handlers so it might be screwing something up. |
Bipolar (III) Inmate From: |
posted 05-26-2006 20:15
there is one little mistake in there, about the "left" and "top" but that wasnt the main problem |
Paranoid (IV) Inmate From: Norway |
posted 05-27-2006 23:51
the javascript: is unecessary but doesn't screw the things up. IMHO what's wrong is the scope of the Refresh variable. It's only declared and assigned in the newWindow function, so it is unknown in the stopIt function. Simply add a code: var Refresh outside of all functions so the variable is available and known from every functions, and voilà. |
Bipolar (III) Inmate From: |
posted 05-28-2006 00:24
ok that helps too thanks |
Paranoid (IV) Inmate From: Dublin, Ireland |
posted 05-28-2006 19:26
Hard to say if its "good" or not, I think having an alternative incase a popup doesnt work is a great idea. Was that your question or where you asking about code efficiency or something along those lines? |
Bipolar (III) Inmate From: Umeå, Sweden |
posted 05-29-2006 01:36
Opera and Firefox popup blockers* are quite sophisticated I think. They are trying to block any way of causing popups that is not a direct effect of user interaction. IIRC they do stuff like marking events as user triggered versus script triggered etc. as filter methods for determining whether the popup should be allowed or not, and default to not allowing it. |