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?

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

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">

Comments

Your Answer

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.