如何将外部网页载入 html 网页的 div

我需要加载一个响应网站到一个 div 在我的 HTML 页面没有使用 iframe元素。

我已经尝试了 这个链接; 它适用于单个页面 URL,我在脚本中提到过这一点。

$('#mydiv').load('http://localhost/qa/ask#external-div', function(response, status, xhr) {
if (status == "error") {
var msg = "Sorry but there was an error: ";
alert(msg + xhr.status + " " + xhr.statusText);
}
});
345156 次浏览

Using simple html,

 <div>
<object type="text/html" data="http://validator.w3.org/" width="800px" height="600px" style="overflow:auto;border:5px ridge blue">
</object>
</div>

Or jquery,

<script>
$("#mydiv")
.html('<object data="http://your-website-domain"/>');
</script>

JSFIDDLE DEMO

As mentioned in this stackoverflow thread, difference between iframe, embed and object elements

You can use <embed> tag, instead of <object> tag. If you require communication between child and parent.

† As pointed out in the comments below; scripts in <object> will run but the parent and child contexts can't communicate directly. With <embed> you can get the context of the child from the parent and vice versa. This means they you can use scripts in the parent to manipulate the child etc. That part is not possible with <object> or <iframe> where you would have to set up some other mechanism instead, such as the JavaScript postMessage API.

<embed type="text/html" src="snippet.html" width="500" height="200">