开发者

Chrome & Safari Error::Not allowed to load local resource: file:///D:/CSS/Style.css

When I access my aspx page in chrome or safari it shows this error in console

Not allowed to load local resource: file:///D:/CSS/Style.css

Everything works fine in IE and FF.

I use an e开发者_StackOverflowxternal CSS which is linked in aspx page via

<link rel="stylesheet" media="all" href="file:///D:/CSS/Style.css" type="text/css" />

I have tried all the combination of "/" & "\" slashes..

Whether I am giving file path in wrong manner or its any security exception in these browsers(I am logged in as administrator)... What am I doing wrong?


You wont be able to access a local resource from your aspx page (web server). Have you tried a relative path from your aspx page to your css file like so...

<link rel="stylesheet" media="all" href="/CSS/Style.css" type="text/css" />

The above assumes that you have a folder called CSS in the root of your website like this:

http://www.website.com/CSS/Style.css


It is today possible to configure Safari to access local files.

  • By default Safari doesn't allow access to local files.
  • To enable this option: First you need to enable the develop menu.
  • Click on the Develop menu Select Disable Local File Restrictions.

Source: http://ccm.net/faq/36342-safari-how-to-enable-local-file-access


The solution is already answered here above (long ago).

But the implicit question "why does it work in FF and IE but not in Chrome and Safari" is found in the error text "Not allowed to load local resource": Chrome and Safari seem to use a more strict implementation of sandboxing (for security reasons) than the other two (at this time 2011).

This applies for local access. In a (normal) server environment (apache ...) the file would simply not have been found.


I know this post is old but here is what I found. It doesn't work when I link it this way(with / before css/style.csson the href attribute.

<link rel="stylesheet" media="all" href="/CSS/Style.css" type="text/css" />

However, when I removed / I'm able to link properly with the css file It should be like this(without /).

<link rel="stylesheet" media="all" href="CSS/Style.css" type="text/css" />

This was giving me trouble on my project. Hope it will help somebody else.


I also encountered the same problem. I provided relative path this resolved the issue

Before path was : c:\images\test\someimage.jpg Updated to : ~images\test
After this I am able to view the images

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜