Pass variable to external JS file?

≡放荡痞女 提交于 2019-11-29 10:24:46

No, you can't pass parameters like that and have the script read them in.

Technically you could grab them from the <script> tag, but that would be a real mess.

Could you just output a script block before you include the file?

<script type="text/javascript"> var timeout = 1000; </script>

try this:

<script>
var myvariable = "foo";
</script>
<script src="/link/to/js.js"></script>
<script type="text/javascript">
var imagesPath = "emblematiq/img/";
</script>
<script type="text/javascript" src="emblematiq/niceforms.js"></script>

This will work fine on server

No, but you can pass a the value directly to a function in that file or set a variable value that will be used in the external file.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!