Calling URL parameters within a .js file

前端 未结 8 2153
北荒
北荒 2021-01-05 01:51

I am calling a .js file within a HTML file. On the URL to the .js file I want to include a parameter that will be accessable to the code INSIDE the .js file.

For exa

8条回答
  •  北海茫月
    2021-01-05 02:17

    You can't do it like that: you have to declare the variable before loading the script. Example:

    
    
    

    in this way, the variable will be ready for your script.

    Another solution is to use a php script, that can then use the GET variable. In that case, make sure you tell via a header() call that you are outputting javascript

    
    

    And the ip.php

    " . $serverIP . "\")";
    ?>
    

提交回复
热议问题