java脚本的绝对文件路径
我有一个自己编写的小型 JavaScript 库。我想在我的 Web 应用程序中引用它,但它不起作用
<script src='file:\\C:\Path\To\Script\Script.js'></script>
当您只知道绝对路径时是否可以引用 javascript?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
file:
url 需要 3 正斜杠,路径也需要正斜杠:当然,只有当您在磁盘上的 html 文件中加载脚本时,这才有效。已加载到您的浏览器中。
The
file:
url needs 3 forward slashes, and the path also needs forward slashes:This will ofcourse only work if you load the script within a html-file on your disk that's loaded in your browser.
虽然我是 Mac 用户,但我对 Windows 安全性的(有限)理解是它对“本地”运行 Javascript 文件有限制。最好的选择是将文件复制到 Web 应用程序的目录结构并通过相对路径引用它。
这不仅会提供更高的可靠性,而且在部署到 Web 服务器或类似服务器时,也少了一件需要记住的事情。如果 JS 文件位于应用程序的文件夹结构之外,则在部署到远程服务器时,无论如何都必须包含它。
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.