Reputation: 113
How I can get variable from another.js file? I have 2 files: script.js actualversion.js
actualversion.js:
var version = '1.1';
Now i need to read this "version" variable to script.js every 60 sec
setInervat(..., 60000);
if(version != currentversion) { alert("UPDATE!"); }
Sorry I forgot.. The "actualversion.js" is in another domain..
Upvotes: 0
Views: 245
Reputation: 4263
If you are using jQuery you could do this;
function checkVersion () {
$.getScript("http://otherDomain.com/actualversion.js", function(){
console.log("Loaded actualversion");
if(version !== currentversion) {
console.log("UPDATE!");
}
})
}
var checkingVersion = setInterval(checkVersion() , 60000);
If you want to cancel the check at some point, you can trigger the following function call and pass your setInterval variable (e.g. checkingVersion) as the argument:
clearInterval(checkingVersion);
The most important thing to be aware of with doing what you are doing, is that when you load actualversion.js, you will be loading the whole file. This means that you will load in all its variables and functions. It's important to make sure that these don't conflict with your own.
Upvotes: 1