Reputation: 6911
I have an external JavaScript function that I need to call in each of my HTML files before the page is rendered (it's setting the locale), each time with a different argument. The script file with the function is included in the <head>
element.
What are the way to pass an argument inside the script before the page is rendered? I'm unable to use hidden <input>
or <div>
then and would like to avoid embedded <script>
calls.
Upvotes: 0
Views: 48
Reputation: 5213
You can just introduce a locale variable in the global scope, within the <head>
section, just before your script is called, and then modify your script to look for that variable.
<head>
<!-- ... -->
<script type="text/javascript">
var locale = "fr-CA";
</script>
<script src="/js/myscript.js" type="text/javascript"></script>
<!-- ... -->
</head>
Upvotes: 2