2

I'm trying to put a code snippet into an external .js. Works fine as is inside the page file but stops working if I pull out the script to an external file. I'm thinking it's a variable issue but I'm not entirely clear how to fix that. Little help. Thanks.

Here's the current working internal code:

<script src="scripts/jquery-1.12.4.min.js"></script>
<script src="scripts/jquery.flurry.js"></script>
<script>
      $(document).ready(function(){
        $("body").flurry({height:300,frequency:98,speed:4321,small:11,large:61,wind:40,windVariance:98,rotation:272,rotationVariance:98,
        startOpacity:1,endOpacity:0,opacityEasing:"cubic-bezier(1,.3,.6,.74)",blur:true,overflow:"hidden",zIndex:9999});
        $(".toggle-snow").on("click",function(event){
          event.preventDefault();
          try{
            $("body").flurry("destroy");}
          catch(err){
            $("body").flurry();}
        });
      });
    </script>

When I pull that third script into a fall.js file, the code stops working. Is there something that I need to add to the external script or the internal file?

-- Ah! Silly me. Needed to just remove the open / closing tag in the fall.js file.

2
  • Show us the code that does not work (HTML + JS). Not the code that works fine. Commented Dec 19, 2016 at 17:29
  • 1. post the way you include the script tag when internal. 2. are you seeing any errors in the console? what do you mean by "stop working"? 3. note that you got a " ' ?>" I suppose shouldn't be there. Commented Dec 19, 2016 at 17:29

2 Answers 2

1

Why do you have the "?>" and inside the fall.js remove the opening and closing tags.

Keep references to the other external files in the html

Before referring to fall.js

Sign up to request clarification or add additional context in comments.

2 Comments

Ah, silly me. Just needed to remove the open/close tag in the fall.js file. The ?> is because the whole thing is wrapped in a php if clause. Forgot to edit it out. Thanks.
RIght. Can you mark this answer right, as it was the cause?
0

How are you trying to register the script?

<script src="scripts/jquery-1.12.4.min.js"></script>
<script src="scripts/jquery.flurry.js"></script>
<script src="fall.js"></script>

This should be enough to make the script work, as long as the fall.js file is served in the /fall.js route

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.