3

我正在尝试加载执行的本地网页:

var html = document.open('google.html');
document.documentElement.innerHTML = html;

它加载页面,但格式不正确,图像不会显示。我怎样才能加载全部内容?

谢谢

4

2 回答 2

3

这很可能是因为允许外部资源(图像、样式表、js 文件等)具有相对 url。任何相对 url 都需要完全限定页面才能正确加载。

于 2012-06-20T11:00:15.283 回答
2

If you want to replace the content of the page by another one, simply do

document.location.href="http://google.com";

If you want to open a local page named google.html do

document.location.href=document.location.href.splitOnLast('/')[0]+"/google.html";

This will ensure that linked resources can be loaded as the relative paths will be accorded to the location of the page. Don't change the content yourself.

于 2012-06-20T11:02:45.393 回答