I have javascript file in following directory
/static
/handler.js
/evercookie.js
/jquery.js
All I want to do from handler.js function call a function in evercookie.js. for example
in handler.js
var ec = new evercookie();
cookiePresent = false
ec.get(suggestion_id, function(value) {
alert("Cookie value is " + value);
cookiePresent = true;
});
if (cookiePresent) {
return;
} else {
ec.set(suggestion_id, "1");
alert("cookie set for " + suggestion_id);
}
where evercookie() is in evercookie.js
when I try this it fails saying evercookie not found
How shall I fix this?
2 Answers 2
Make sure that the order of your scripts is correct - evercookie.js needs to be referenced before any other script can use it.
From:
/handler.js
/evercookie.js
/jquery.js
To:
/jquery.js
/evercookie.js
/handler.js
The browser parses and interprets HTML, CSS and JavaScript top-down so if you try to access a property or instantiate an object that doesn't exist the browser will error...
More on Browser Parsing:
1 Comment
You have to either just put the evercookie.js code above the code in your handler.js file, or you have to link to evercookie.js BEFORE you link to handler.js.
<script src="static/evercookie.js">
<script src="static/handler.js">