通过 HTTP 服务器上的父级目录访问 HTML 中的 JavaScript 文件
Accessing JavaScript file in HTML through parent level directories on an HTTP server
我正在尝试访问 hellotest.js,它位于我的 index2.html 文件的父目录中。
我没有运气这样做,修复应该很简单,我已经尝试寻找答案。
文件的绝对路径是 (Ubuntu/Linux):
/home/petrus/dev/testbeds/http-server/index2.html
/home/petrus/dev/testbeds/hellotest.js
编辑:我 运行 在 http 服务器上:http-server, SimpleHTTPServer
<!DOCTYPE HTML>
<html>
<head>
<script src="../hellotest.js" type="text/javascript"></script>
<title>test website</title>
</head>
<body>
<p>hello world 2</p>
</body>
</html>
不要使用 .. 向上导航到父目录,只需使用目录名称即可。尝试 testbeds/hellotest.js。
我最终通过创建符号链接解决了这个问题。
在 Linux/Ubuntu 中,您可以使用:ln -s <symlink_origin> <symlink_destination
我正在尝试访问 hellotest.js,它位于我的 index2.html 文件的父目录中。
我没有运气这样做,修复应该很简单,我已经尝试寻找答案。
文件的绝对路径是 (Ubuntu/Linux):
/home/petrus/dev/testbeds/http-server/index2.html
/home/petrus/dev/testbeds/hellotest.js
编辑:我 运行 在 http 服务器上:http-server, SimpleHTTPServer
<!DOCTYPE HTML>
<html>
<head>
<script src="../hellotest.js" type="text/javascript"></script>
<title>test website</title>
</head>
<body>
<p>hello world 2</p>
</body>
</html>
不要使用 .. 向上导航到父目录,只需使用目录名称即可。尝试 testbeds/hellotest.js。
我最终通过创建符号链接解决了这个问题。
在 Linux/Ubuntu 中,您可以使用:ln -s <symlink_origin> <symlink_destination