如何将外部网页加载到 html 页面的 div 中 [英] How to load an external webpage into a div of a html page

查看:34
本文介绍了如何将外部网页加载到 html 页面的 div 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在不使用 iframe 元素的情况下将响应式网站加载到我的 HTML 页面中的 div 中.

我已经尝试过这个链接;它适用于我在脚本中提到的单个页面 URL.

$('#mydiv').load('http://localhost/qa/ask#external-div', function(response, status, xhr) {如果(状态==错误"){var msg = "抱歉,出现错误:";警报(味精 + xhr.status + " " + xhr.statusText);}});

解决方案

使用简单的 html,

 

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

或者jquery,

JSFIDDLE 演示

I need to load a responsive website into a div in my HTML page without using an iframe element.

I have tried this link; it's working for a single page URL, which I mentioned in the script.

$('#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);
      }
});

解决方案

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

这篇关于如何将外部网页加载到 html 页面的 div 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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