1

I am trying to call another function in a different HTML file would I do something like this:

 <script type = "text/javascript" src = "otherfile.html"></script>

This is the function getting called

        function rankedScores(music, pattern) { 
            var scoresArray = urlScores(music, pattern);  

            function swap(a, b) {
                var temp = scoresArray[a];
                scoresArray[a] = scoresArray[b];
                scoresArray[b] = temp;
            }

            for(var i = 0; i < scoresArray.length; i++) {
                for(var x = 0; x < scoresArray.length - 1; x++) {

                    if (scoresArray[x].score > scoresArray[x + 1].score) {
                        swap(x, x + 1);
                    }
                }
            }
            generateResults(scoresArray)
        }

This is how im calling it:

       rankedScores(albums, document.main.search.value);
Pavlo
  • 43,301
  • 14
  • 77
  • 113
user2964960
  • 29
  • 1
  • 9
  • 3
    Move it to a JS file. – SLaks Dec 08 '13 at 20:26
  • If one of the pages is in an iframe, you can call its functions [from the parent window](https://stackoverflow.com/questions/251420/invoking-javascript-code-in-an-iframe-from-the-parent-page). – Anderson Green Feb 27 '22 at 12:48

1 Answers1

4

You cannot do this. You should move it into a js file and then include that js file in your template:

<script type='text/javascript' src='some_other_file.js'></script>
Ryan Bigg
  • 106,965
  • 23
  • 235
  • 261