jQuery 如何将外部网页加载到 html 页面的 div 中
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18145273/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 21:06:16 来源:igfitidea点击:
How to load an external webpage into a div of a html page
提问by user2089987
I need to load a responsive website into a div in my HTML page without using an iframe
element.
我需要在不使用iframe
元素的情况下将响应式网站加载到我的 HTML 页面中的 div 中。
I have tried this link; it's working for a single page URL, which I mentioned in the script.
我试过这个链接;它适用于我在脚本中提到的单个页面 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);
}
});
回答by Optimus Prime
Using simple html,
使用简单的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,
或者jquery,
<script>
$("#mydiv")
.html('<object data="http://your-website-domain"/>');
</script>