2

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?

M.Babcock
19k6 gold badges57 silver badges85 bronze badges
asked Jan 2, 2012 at 2:40

2 Answers 2

3

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:

http://www.whatwg.org/specs/web-apps/current-work/multipage/parsing.html#overview-of-the-parsing-model

answered Jan 2, 2012 at 2:42
Sign up to request clarification or add additional context in comments.

1 Comment

Xander what does that mean and how it affects?
1

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">
answered Jan 2, 2012 at 2:44

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.