admin管理员组文章数量:1333450
I'm writing a script for the serial extraction of information from a page, in general I have to pause javascript, but that the page continues to load, and the javascript stopped.
setTimeout is not necessary, since the rest of the script is still running
I need it in order to make the script continues to run after the other script (which I do not have access) download the necessary data to the page (this takes 3 seconds).
P.S. If there is something I pull information from the village - / using mozilla with extention "user script"
I'm writing a script for the serial extraction of information from a page, in general I have to pause javascript, but that the page continues to load, and the javascript stopped.
setTimeout is not necessary, since the rest of the script is still running
I need it in order to make the script continues to run after the other script (which I do not have access) download the necessary data to the page (this takes 3 seconds).
P.S. If there is something I pull information from the village - http://www.mosgortrans/pass3/ using mozilla with extention "user script"
Share Improve this question asked Dec 1, 2012 at 10:28 Ilya KharlamovIlya Kharlamov 1251 gold badge1 silver badge10 bronze badges 1- 3 rather than pausing the script, I would fire an event and write my logic in that event handler code in the js. This way it is not dependent on number of seconds i.e 3 or 5 or anything. – Mandar Commented Dec 1, 2012 at 10:45
2 Answers
Reset to default 2I don't see why setTimeout
is not necessary here - it does exactly what you describe:
setTimeout(function() {
// this code runs 3 seconds after the page loads
}, 3000);
As the previous answer and ment have suggested, the normal way of doing this would be to put the code you want to run after the script loads in a function in setTimeout
. If you are worried, for instance, about event handlers being triggered while you are waiting and causing an error, then you need to disable the event handlers (e.g. element.onclick = null
) then re-enable them within the time-out function. I suppose you could also do something like this:
var pause = false;
...
callExternalScript();
pause = true;
setTimeout(function() {
pause = false;
}, 3000);
...
function oneOfMyOtherFunctions() {
if (pause) return;
...
}
...
but this is messy because you have to include if (pause) return
at the start of every function that you want to disable while the script is paused. Also you may or may not want to add extra code to run all those functions that were called while the script was paused, once it has been un-paused.
本文标签: htmlsleepwaitpause javascriptStack Overflow
版权声明:本文标题:html - sleepwaitpause javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742353228a2458907.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论