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

后端 未结 4 971
时光说笑
时光说笑 2021-01-16 01:00

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.

4条回答
  •  忘掉有多难
    2021-01-16 01:55

    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.

提交回复
热议问题