开发者

Problem in reference js file for IE7/8

I have a very strange problem in an AS开发者_StackOverflowP.NET page, the following reference of JavaScript file works well in IE6

<script src='~/Scripts/xxx.js'  type="text/javascript"></script>

But not working in IE7/8, I got object required error when load the page change to the following works:

<script src='<%# ResolveUrl ("~/Scripts/xxx.js") %>'  type="text/javascript"></script>

Can anyone explain? Thanks.


~/ is not going to be anything the browser knows about, it needs to be a relative path or an absolute one. The ResolveUrl method take an asp.net path and creates one the browser can understand.


Use this:

<script src="<%= Response.ApplyAppPathModifier("~/Scripts/xxx.js") %>" type="text/javascript"></script>

Basically, the "~" is a way to refer to the application's home directory, but it is only understood by ASP.NET. You can call the function I listed above to translate that into a real HTTP path.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜