如何使用Javascript在div中加载网页而不使用IFRAME和JQuery? [英] How do I load a webpage inside a div using Javascript without IFRAME and JQuery?

查看:111
本文介绍了如何使用Javascript在div中加载网页而不使用IFRAME和JQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将外部网页加载到div。我不想使用iFrame。我想用简单的Javascript做。

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.

推荐答案

遇到困难...

使用Ajax(例如,通过 XMLHttpRequest )获取页面。由于它是外部的,因此您需要绕过相同的原始政策

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

一旦你有了页面,提取它的相关部分(可能是 body 元素的子项)并将其添加到您现有的DOM

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.

您需要考虑网站和外部网站之间的不同样式表,相对URI(对外部网站上不属于您的资源)以及任何脚本

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.

这篇关于如何使用Javascript在div中加载网页而不使用IFRAME和JQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆