最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

search - Does Javascript <script src =...> accept full path? - Stack Overflow

programmeradmin2浏览0评论

If I have a directory structure like so

/
├── home
│   └── user
│       └── test.js
├── usr
│   └── bin
└── var
    └── www
        └── index.html

Putting aside folder permissions for the moment, if index.html had the following line

<script src="../../../home/user/test.js">

or

<script src="/home/user/test.js">

Would this be valid? If so, is there any way to prevent this so only nested folders can be reached (EDIT symbolic links must also be ignored)?

If I have a directory structure like so

/
├── home
│   └── user
│       └── test.js
├── usr
│   └── bin
└── var
    └── www
        └── index.html

Putting aside folder permissions for the moment, if index.html had the following line

<script src="../../../home/user/test.js">

or

<script src="/home/user/test.js">

Would this be valid? If so, is there any way to prevent this so only nested folders can be reached (EDIT symbolic links must also be ignored)?

Share Improve this question asked Nov 7, 2011 at 1:56 pukpuk 16.8k31 gold badges125 silver badges206 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

The browser will attempt to access whatever path is in the src attribute. You can restrict certain paths by setting file permissions through your web server (eg. Apache).

It is valid. It's the web server's job to serve or not to serve the file.

If you use /home/user/test.js however, that's usually relative to the document root, so it's equivalent to http://<host>/home/user/test.js.

<script src="/home/user/test.js">

would be valid. It would just use whatever domain was on the host web page and would start from the top level directory there. For example, if the host web page was:

http://www.example./projectA/test.html

then <script src="/home/user/test.js"> would generate a request for the file at this location:

http://www.example./home/user/test.js

发布评论

评论列表(0)

  1. 暂无评论