Topic: Javascript problem (Page 1 of 1) |
|
---|---|
Bipolar (III) Inmate From: |
![]() 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 |
![]() 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: |
![]() there is one little mistake in there, about the "left" and "top" but that wasnt the main problem |
Paranoid (IV) Inmate From: Norway |
![]() 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: |
![]() ok that helps too thanks |
Paranoid (IV) Inmate From: Dublin, Ireland |
![]() 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 |
![]() 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. |