在我的项目中,用户可以输入网站的 URL,系统就会从该网站获取所有图像。由于图像的 src
可以是相对的,系统会将其“规范化”,因此:
- src="http://host.com/image1.png" 的图像将变为“http://” host.com/image1.png”(无变化)
- 带有 src="/image2.png" 的图像变为“http://host.com/image2.png”(前置主机)
- “http://host”上的图像.com/sub/dir/page.html" 与src="image3.png" 变为 "http://host.com/sub/dir/image3.png" (前置主机和路径)
现在看看这个页面,如果可以的话:
http://www.presentkuriren.se/presenter/4/728/Karlek/Pasta---hjartan.html< /a>
如果你看一下源代码,主图像的实现为
这会让我得出这样的结论:绝对路径是http://www.presentkuriren.se/presenter/4/728/Karlek/prodbilder/ Large/JJI10002.jpg,但事实并非如此。它是 http://www.presentkuriren.se/prodbilder/large/JJI10002.jpg 并且所有浏览器似乎理解这一点并正确显示它......
我有点困惑,觉得我错过了一些明显的东西......请向我指出!
In my project users can enter the URL of a website and the system goes and fetches all images from this website. Because the src
of the image can be relative, the system "normalizes" it, so:
- an image with src="http://host.com/image1.png" becomes "http://host.com/image1.png" (no change)
- an image with src="/image2.png" becomes "http://host.com/image2.png" (prepend host)
- an image on "http://host.com/sub/dir/page.html" with src="image3.png" becomes "http://host.com/sub/dir/image3.png" (prepend host and path)
Now take a look at this page if you may:
http://www.presentkuriren.se/presenter/4/728/Karlek/Pasta---hjartan.html
If you have a look at the source code, the main image is implemented as <img src="prodbilder/large/JJI10002.jpg"...
This would lead me to the conclusion that the absolute path is http://www.presentkuriren.se/presenter/4/728/Karlek/prodbilder/large/JJI10002.jpg, which it is not. It's http://www.presentkuriren.se/prodbilder/large/JJI10002.jpg and all browsers seem to understand that and display it correctly...
I'm slightly baffled and feel like I'm missing something obvious... please point it out to me!
发布评论
评论(1)
头部有
标签:因此所有相对 URL(来自图像、链接等)都与此相对!
There's the
<base />
tag in the head:So all relative URLs (from images, links, ...) are relative to this one!