简体   繁体   English

如何链接到根目录中的文件

[英]How to link to file in root directory

I have a website with index.html in the root folder, and a folder named apples . 我有一个网站,其根文件夹中有index.html ,还有一个名为apples的文件夹。 Inside apples I have another index.html . apples内部,我还有另一个index.html Currently I am attempting to use AngularJS to load the same navbar into both pages. 目前,我正在尝试使用AngularJS将相同的导航栏加载到两个页面中。 However, when I tried linking to the Javascript file like so: <script src="/controller.js"> , the JS file loads for the index.html in the root folder, but it refuses to load the file for the index.html in the apples folder. 但是,当我尝试像这样链接到Javascript文件: <script src="/controller.js"> ,JS文件将在根文件夹中为index.html加载,但拒绝为index.html加载该文件index.html apples文件夹中的index.html Does anyone know why? 有人知道为什么吗? In the apples folder, it keeps linking to apples//controller.js . apples文件夹中,它一直链接到apples//controller.js

<script src="../js/controller.js"></script>
          __ ______ ________
          |    |       |
          |    |       |___ 3. Get the file named "logo.png"
          |    |
          |    |___ 2. Go inside "images/" subdirectory
          | 
          | 
          |____ 1. Go one level up

Reference 参考

Are you running this on a server or just on your desktop? 您是在服务器上还是在桌面上运行它? The path /controller.js should work if you're running from a web server but likely won't work if you're calling it locally. 如果从Web服务器运行,则/controller.js路径应该可以工作,但是如果在本地调用,则可能无法工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM