Javascript 如何在div中加载网页?

Javascript 如何在div中加载网页?,javascript,jquery,css,html,Javascript,Jquery,Css,Html,有点问题 未声明doctype的网页包含div id=“abc”。我需要在此div中加载一个doctype为的网页。他们在怪癖模式下渲染的主要问题,这会导致外观问题 div“abc”是一个弹出窗口,具有绝对位置 Content is loaded on user request , content is dynamic and built using PHP and can't provide url to achieve this . 有任何方法可以在不改变任何页面内容类型的情况下获得与H

有点问题

未声明doctype的网页
包含
div id=“abc”
。我需要在此div中加载一个
doctype为
的网页。他们在
怪癖模式下渲染的主要问题,这会导致外观问题

div“abc”是一个弹出窗口,具有绝对位置

Content is loaded on user request , content is dynamic and built using PHP 
and can't provide url to achieve this .

有任何方法可以在不改变任何页面内容类型的情况下获得与HTML5相同的外观。

因为div容器是当前werbsite的一部分,它接受来自主网站的css样式和其他内容。在div容器中启动新的HTML标记时,HTML代码甚至无效

使用iframe标记,它专门用于创建“网站中的网站”:


这样一来,即使w3c验证程序也不会有问题,您的css和脚本也不会被之前包含或执行的任何其他脚本覆盖

编辑:

如果您需要按照您告诉我的那样动态加载内容,请使用JQuery更改iframe的src:

如果iframe在开始时未初始化,请将其隐藏:

<iframe id="content_iframe" src="" height="1000" width="500" style="display: none";></iframe>

然后使用jQuery、通过ajax或任何其他方式加载内容:

<script type="text/javascript">
    $(document).ready(function() {
        $.ajax({
          url: "path/to/my/url-to-get-my-url-or-content.php",
          type: "post",
          data: any: var },
          success: function(text) {
              //Lets assume I got the target url for the iframe, then just alter its src tag and make it visible:
              $("#content_iframe").attr("src", text);
              //And make it visible with a cool effect :P
              $("#content_iframe").show("slow");

              //Incase you do not have the URL but the raw content, just use function html instead and make it visible same way:
              $("#content_iframe").html(text);
              $("#content_iframe").show("slow");
          },
          error: function() {
               alert("Something went wrong, oops!");
          }
        });
    });
</script>

$(文档).ready(函数(){
$.ajax({
url:“path/to/my/url以获取我的url或content.php”,
类型:“post”,
数据:any:var},
成功:函数(文本){
//假设我获得了iframe的目标url,然后只需更改其src标记并使其可见:
$(“#content_iframe”).attr(“src”,text);
//并使其具有一种凉爽的效果:P
$(“内容框架”).show(“慢”);
//如果您没有URL,但有原始内容,只需使用函数html,并以相同的方式使其可见:
$(“#content_iframe”).html(文本);
$(“内容框架”).show(“慢”);
},
错误:函数(){
警惕(“出了点问题,哎呀!”);
}
});
});

你的任务完成了

我必须动态添加内容。使用JavaScript还是PHP?我猜是第一个,但在我给出答案之前先确定一下……不过你可以隐藏Iframe并放置一个空的src标记,然后使用JQuery动态放置内容……页面是使用PHP在服务器上构建的,并使用Ajax调用发送回调用方函数。我得到了你的答案,但无法提供url。请尝试,因为html可以通过以下方式动态加载文件:Ajax@TheOneandOnlyChemistryBlobCoent是根据用户请求加载的,所以我不能使用OK…你能使用Ajax并根据用户的请求回显正确的内容吗?@TheonendonlyChemistryblob回显不起作用,因为doctype是不同的。好吧…明白了---->iframe
<script type="text/javascript">
    $(document).ready(function() {
        $.ajax({
          url: "path/to/my/url-to-get-my-url-or-content.php",
          type: "post",
          data: any: var },
          success: function(text) {
              //Lets assume I got the target url for the iframe, then just alter its src tag and make it visible:
              $("#content_iframe").attr("src", text);
              //And make it visible with a cool effect :P
              $("#content_iframe").show("slow");

              //Incase you do not have the URL but the raw content, just use function html instead and make it visible same way:
              $("#content_iframe").html(text);
              $("#content_iframe").show("slow");
          },
          error: function() {
               alert("Something went wrong, oops!");
          }
        });
    });
</script>