简体   繁体   中英

Preventing a js file from being called twice

Is there a way to put a variable in a javascript file so that it increments whenever the file is called (like a static var in Java)? I want to use it to prevent calling a js file twice. Or, is there another way to do this?

var checkit = window.check_var;

if(checkit === undefined){ //file never entered. the global var was not set.
    window.check_var = 1;
}
else {
    alert('FILE WAS CALLED ALREADY!');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM