testing123
testing123

Reputation: 829

Creating external .js

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.

Upvotes: 2

Views: 154

Answers (2)

thalesmello
thalesmello

Reputation: 3439

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

Upvotes: 0

tgkprog
tgkprog

Reputation: 4608

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

Upvotes: 1

Related Questions