admin 管理员组文章数量: 1086019
Hy my question really is about how to kill an already onload redirection.
I'v got a between page opening, that's set for an 10 sec delay before going to the 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 the HTML body i'v got some 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 what I WANT is to always have the setTimeout redirection active, but if in those 10 sec. user clicks on the checkbox or the bookmark button, i want it to break/stop.
PSEUDO:
onload: setTimeOut(URL,10sec); - 1,..2,..3,..
listener: if(#div1 || #div2 || ..#divN) are clicked? -> immediately STOP/BREAK setTimeout (kill the 10 seconds bomb)
ps (side Q): I use jquery, and have set onload after dom.ready() because in that whay dom.ready is always a little faster than onload. Is there gonna be a race problem because of this?
Hy my question really is about how to kill an already onload redirection.
I'v got a between page opening, that's set for an 10 sec delay before going to the 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 the HTML body i'v got some 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 what I WANT is to always have the setTimeout redirection active, but if in those 10 sec. user clicks on the checkbox or the bookmark button, i want it to break/stop.
PSEUDO:
onload: setTimeOut(URL,10sec); - 1,..2,..3,..
listener: if(#div1 || #div2 || ..#divN) are clicked? -> immediately STOP/BREAK setTimeout (kill the 10 seconds bomb)
ps (side Q): I use jquery, and have set onload after dom.ready() because in that whay dom.ready is always a little faster than onload. Is there gonna be a race problem because of this?
Share Improve this question asked Jan 26, 2011 at 9:28 PathOfNeoPathOfNeo 1,0894 gold badges21 silver badges39 bronze badges2 Answers
Reset to default 6declare the timeout in a variable:
var t = window.setTimeout('redirect(strUrl)', 10000);
and later use that variable
clearTimeout(t);
to kill it
more here
besides that: use document.ready() OR onload , to prevent yourself from frenzy-racing conditions.
var mytimer = window.setTimeout('redirect(strUrl)', 10000);
/*....*/
if (condition){
clearTimeout(mytimer)
}
本文标签:
版权声明:本文标题:javascript - KILL THE timed delay function "setTimeout redirecting to page" IF SOME UI elements are clicked - 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744099661a2533439.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论