【问题标题】:Load web link to div or iframe将网页链接加载到 div 或 iframe
【发布时间】:2013-01-08 20:24:40
【问题描述】:

这可能是常见问题。我看到了几个关于这个问题的答案。

  1. 使用 jquery 加载
  2. 使用 iframe

我尝试了这两种方法,但无法轻松加载。 这是为了加载 google.com,但它不起作用。

<html>
    <head>
        <title>hhh</title>
        <script src="jquery.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                $("#content").attr("src","http://www.google.lk/");
            })
        </script>
    </head>
    <body>
        <iframe id="content" src="about:blank"></iframe>
    </body>
</html>

但是当我尝试加载 w3schools.com 时,它会加载到 iframe 中

<html>
    <head>
        <title>hhh</title>
        <script src="jquery.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                $("#content").attr("src","http://w3schools.com/");
            })
        </script>
    </head>
    <body>
        <iframe id="content" src="about:blank"></iframe>
    </body>
</html>

当使用 jQuery 加载时它也不起作用。

<html>
    <head>
        <script src="jquery.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                $("#content").load("src","http://www.google.com/");
            })
        </script>
    </head>
    <body>
        <div id="content" src="about:blank"></div>
    </body>
</html>

在萤火虫栏中用“GET http://www.google.com 302 Found 291ms”显示这个

一些身体帮助我摆脱这个。

【问题讨论】:

  • 你想做什么?
  • @Chanckjh : 请原谅错别字,不是每个人的英语都写得很好
  • 我猜这是这个的副本:stackoverflow.com/questions/8524449/…
  • @JFK 是的,但 iframe 不是真的英文
  • 您使用 .load 错误(作为记录)例如。 $('#content').load('google.com/');

标签: javascript jquery html css


【解决方案1】:

使用 jquery load 在 div 中显示内容。 div 没有src

影响srciframe 告诉您的浏览器获取内容并将其显示在 iframe 中。

load() 的正确语法是:

<div id="content"></div>

$("#content").load("page.php");

顺便说一句,google.com 不喜欢从其他网站加载,所以您最好使用其他示例。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-30
    • 2012-07-22
    • 1970-01-01
    • 2013-03-20
    • 2016-02-07
    • 1970-01-01
    相关资源
    最近更新 更多