Jump to content

How to display an external page without breaking external resources


joeami

Recommended Posts

Hi All,

 

I'm developing a small app where I display an HTML page on a browser to end users. The closest thing to what I'm trying to do would be Google's cache functionality. For example, let's say someone decided to use my app and requests that google.com be display, then my app would display a copy of google.com's index/content on the browser. Because this is done via mydomain.tld, mydomain.tld is the document.domain.

 

Which brings me to the problem, if google has a href or img with a src="/image.jpg" with window.onload(), the browser would attempt to pull http://mydomain.tld/image.jpg and therefore breaks the page display.

 

My question is how do I force the browser to inject the correct domain name? mydomain.tld so in control of the DOM. But I'm not sure how to get there.

 

Any help is appreciated.

 

Regards

Link to comment
Share on other sites

You'll need to manually replace every relative URL, I'd suggest using the DOM extension as opposed to regexp or something like that. Have a play around, load the HTML with the loadHTML method, navigate through the child nodes and see what you can do.

 

When you get stuck come back and I'll gladly help you, but you'll learn a lot more if you attempt this yourself.

Link to comment
Share on other sites

  • 2 weeks later...

You'll need to manually replace every relative URL, I'd suggest using the DOM extension as opposed to regexp or something like that. Have a play around, load the HTML with the loadHTML method, navigate through the child nodes and see what you can do.

 

When you get stuck come back and I'll gladly help you, but you'll learn a lot more if you attempt this yourself.

 

Thanks for your help. I'm now able to work around the broken images part. I have another issue I need help with. I'll open a new thread on that.

 

Best

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.