javascript - KILL THE timed delay function "setTimeout redirecting to page" IF SOME UI elements are clicked -
hy question how kill onload redirection.
i'v got between page opening, that's set 10 sec delay before going destination:
var strurl = /*from query string, or somewhere else..*/ window.onload = function() { window.settimeout('redirect(strurl)', 10000); } function redirect(strurl) { document.location=strurl; }
now in html body i'v got ui elements, 2 buttons (continue, bookmark), 1 checkbox (don't show anymore,..)
something like:
<body onorientationchange="smartorientation();"> <div id="img_logo"> <img src="#"> </div> <div id="txt"> <p> ...blabla... </p> </div> <div id="btn_bookmark"> <a href="" class="button green" name="name" type="submit" value="bookmark">bookmark </a> </div> <!-- checkboxes,..etc --> </body>
now want have settimeout redirection active, if in 10 sec. user clicks on checkbox or bookmark button, want break/stop.
pseudo:
onload: settimeout(url,10sec); - 1,..2,..3,..
listener: if(#div1 || #div2 || ..#divn) clicked? -> stop/break settimeout (kill 10 seconds bomb)
ps (side q): use jquery, , have set onload after dom.ready() because in whay dom.ready little faster onload. there gonna race problem because of this?
declare timeout in variable:
var t = window.settimeout('redirect(strurl)', 10000);
and later use variable
cleartimeout(t);
to kill it
besides that: use document.ready() or onload , prevent frenzy-racing conditions.
Comments
Post a Comment