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

html - Chrome is loading a local image, but not Firefox. What is the problem? - Stack Overflow

programmeradmin3浏览0评论

I have a very simple HTML file, this is the body:

<body>
    <a href=";>
        <img src="./youtubeLogo.png" alt="YouTube">
        <h1>YouTube</h1>
    </a>
</body>

The issue is that the image is not working in Firefox. It works as expected in Chrome, but not Firefox. I cannot figure any reason why this is happening. I see no errors in Firefox, just "Could not load the image" when I hover it in the inspector.

This is just a local file, no server. Just directly opening it in the browser. Why will the image not load in Firefox?

I have a very simple HTML file, this is the body:

<body>
    <a href="https://youtube">
        <img src="./youtubeLogo.png" alt="YouTube">
        <h1>YouTube</h1>
    </a>
</body>

The issue is that the image is not working in Firefox. It works as expected in Chrome, but not Firefox. I cannot figure any reason why this is happening. I see no errors in Firefox, just "Could not load the image" when I hover it in the inspector.

This is just a local file, no server. Just directly opening it in the browser. Why will the image not load in Firefox?

Share Improve this question asked Feb 15 at 22:50 Lee ManLee Man 6962 gold badges8 silver badges31 bronze badges 5
  • Think about this: ./youtubeLogo.png — relative to what directory? :-) – Sergey A Kryukov Commented Feb 16 at 7:46
  • The ./ means current working directory. The directory that the html file is in. – Lee Man Commented Feb 16 at 14:50
  • No ./ means path relative to some directory. Some base directory. It could be current directory, it could be executable directory, it depends on what application does. The standards define the processing of relative paths in some artifacts, files, such as HTML. But who told you that the address line is processed this way? – Sergey A Kryukov Commented Feb 16 at 15:08
  • "." means current directory. That is always how it has worked. In this case the directory in which the current HTML is located. This is how it has always worked. Try it, it works. You don't necessarily need to start with "./", but "." refers to current working directory. – Lee Man Commented Feb 17 at 17:21
  • Here is a video for you to learn how HTML file paths work: youtube/watch?v=hxto_sRZsBg – Lee Man Commented Feb 17 at 17:21
Add a comment  | 

3 Answers 3

Reset to default 0

The reason is the very fact that it is a local file. Browser access to the file system is a security concern and treated slightly different by vendors.

The strict origin policy for file URIs in firefox will most likely be the cause.

The question is, if you only want this solved for yourself and on your own machine. Then you can type:

about:config

into your Firefox address field.

Browse and change the following setting to false:

security.fileuri.strict_origin_policy

Please consider the implications of lowering your security on that machine. It may not be a big issue on an offline machine, that doesn't browse risky content etc.

This will not solve the issue for viewers on other machines, unless they make the same changes to their config.

It seems that there is no issue with the links, they work perfectly fine. I tested this on multiple different browsers, including Firefox on other machines, everything works perfectly fine.

Despite what other answers/comments claim, this works fine in Firefox and Chrome. You don't need to change settings or use an absolute path.

My issue seems to have been some settings or plugins in my browser that I have changed. Haven't figure out what those are yet, but the image links work normally.

Firefox has some strict rules for the local files, while Chrome is lenient. That is why you have issues like this. Use absolute path <img src="file:///C:/path/to/youtubeLogo.png" alt="YouTube>

发布评论

评论列表(0)

  1. 暂无评论