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?
Make sure that the order of your scripts is correct –
evercookie.jsneeds to be referenced before any other script can use it.From:
To:
The browser parses and interprets
HTML,CSSandJavaScripttop-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:
http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#overview-of-the-parsing-model