Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I load a webpage inside a div using Javascript without IFRAME and JQuery?

I need to load an external webpage into a div. I don't want to use an iFrame. And I want this done with plain Javascript. I'm not sure how to go about it.

like image 247
Jay Avatar asked Jun 23 '26 23:06

Jay


1 Answers

With difficulty…

Use Ajax (e.g. via XMLHttpRequest) to get the page. Since it is external, you will need to bypass the same origin policy.

Once you have the page, extract the relevant parts of it (probably the children of the body element) and add that to your existing DOM.

You'll need to account for differing stylesheets between your site and the external one, for relative URIs (to resources on the external site that aren't on yours), and for any scripts in the remote content.

like image 182
Quentin Avatar answered Jun 25 '26 14:06

Quentin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!