Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
47
rated 0 times [  49] [ 2]  / answers: 1 / hits: 15676  / 12 Years ago, sat, december 1, 2012, 12:00:00

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.org/pass3/ using mozilla with extention user script


More From » html

 Answers
6

As the previous answer and comment 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.


[#81674] Friday, November 30, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
karivictoriab

Total Points: 530
Total Questions: 90
Total Answers: 95

Location: Honduras
Member since Sun, Dec 26, 2021
2 Years ago
;