如何在div中加载网页?

时间:2014-08-15 04:02:24

标签: javascript jquery html css html5

有点问题。

网页whose doctype is not declared包含div id="abc"。我需要在这个doctype is <! DOCTYPE>的div中加载一个网页。他们在quirk mode中呈现的主要问题,这会导致外观问题。

div&#34; abc&#34;是一个弹出窗口,具有绝对位置。

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

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

1 个答案:

答案 0 :(得分:1)

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

使用iframe标记,而不是特别用于创建“网站中的网站”:

<iframe src="http//path/to/my/site" height="1000" width="500"></iframe> 

即便这样,w3c验证器也不会出现问题,您的css和脚本也不会被之前包含或执行的任何其他脚本覆盖。

编辑:

如果您需要动态加载内容,因为您告诉我使用JQuery来更改iframe的src:

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

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

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

<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>

你做完了!

相关问题