Absolute file path for java script

半城伤御伤魂 提交于 2019-11-27 06:09:51

问题


I have a small javascript library written by myself. I want to reference it in my web application, but it doesn't work

<script src='file:\\C:\Path\To\Script\Script.js'></script>

Is it possible to reference javascript when all you know is the absolute path?


回答1:


The file: url needs 3 forward slashes, and the path also needs forward slashes:

<script src='file:///C:/Path/To/Script/Script.js'></script>

This will ofcourse only work if you load the script within a html-file on your disk that's loaded in your browser.




回答2:


Though I'm a Mac guy, my (limited) understanding of Windows security is that it has restrictions around running Javascript files "locally." Your best bet would be to copy the file to your web application's directory structure and reference it through a relative path.

Not only will this provide greater reliability, but it's also one less thing to remember to include when deploying to a web server or somesuch. If the JS file is outside your app's folder structure, when deploying to a remote server you'll have to include it anyways.



来源:https://stackoverflow.com/questions/6395367/absolute-file-path-for-java-script

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