I'm trying to load a local web page executing:
var html = document.open('google.html');
document.documentElement.innerHTML = html;
It loads the page but it's not well formatted and images won't display. How could I load the entire contents?
Thanks
Most likely this is because external resources (images, style sheets, js files etc) are allowed to have relative urls. Any relative urls need to be fully qualified for the page to load properly.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With