开发者

how a browser open a saved html page

how a browser open a saved html page ? It must have to run html file and other files from h开发者_StackOverfloward-disk. But how can a browser find the link of the other small files ? Is a browser change the link of the other small files of html page from url to hard-disk location? How it can do that? I want to do the same thing in my application. But I could not figure out the process.


Most browsers store attached resources (Style sheets, images, scripts and the like) in a separate folder named after the saved page.

All references to resources are then converted to relative references, like so:

<img src="name_of_saved_folder/image.jpg">

the browser will then look in name_of_saved_folder relative to the saved HTML document's location.

If the HTML file is moved to a different locations, the references will usually no longer work.

Internet Explorer introduced the very interesting concept of an archived HTML format in 1999 that combines all resources in one file, but sadly, this hasn't yet caught on in terms of global, real-world support in all browsers.

Instead of coding this on your own, you may be able to interface with an existing tool like wget that can do all the grabbing for you. For most programming languages, there are probably related questions on Stack Overflow already on how to best store a HTML page and its resources locally.


You just have to use relative URLs, so the browser will load the external files (images, etc) relatively to the location of the HTML page.

So if your HTML page is saved at file:///some/directory/page.html, if you have a <img src="image.png">, the browser will load this image from file:///some/directory/image.png.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜