开发者

<!-- #include file = "file.js"> does not work

I have some legacy html code that uses #include file = "filename.js" derective to load .js files to html page. The problem is that the files are not loaded. When I try script src attribute it works fine, that means that the path is right. I use vs2003, windows XP Pro, IIS 5.1 . Do you have any idea why the .js files are not loaded开发者_StackOverflow社区 when I use #include file derective.

Thanks a lot, Daniel


The #include directive is a server side function, not something that the browser does. Therefore you can't verify that the file name is correct by using it in a script tag, as that is loaded by the browser.

If you try to include a file that doesn't exist, the server will return an HTTP 404 error message, it will not silently ignore the #include.

The page has to be processed by the server for the #include tag to work, i.e. it has to have a file type that the script engine handles like .asp or .shtml. If you put an #include tag in an .htm or .html file, it won't be processed.

A proper #include tag looks like this:

<!--#include file="filename.js"-->

It can also use virtual addressing, i.e. the path originates from the root instead of the folder where the page is:

<!--#include virtual="filename.js"-->

Note that the file that you are including has to have a script tag in it to be treated as script by the browser, or you have to put a script tag around the include:

<script type="text/javascript"><!--#include file="filename.js"--></script>


Include file requires your server to be configured properly for the allowance of Server-Side-Includes. Take a look at Microsoft's IIS 5.1 information on setting up ASP and SSI on your XP box: Microsoft IIS SSI Setup. Navigate to the section titled: ASP and SSI settings on IIS

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜