简体   繁体   中英

Load web link to div or iframe

This may be common problem.I saw several answers for this matter.

  1. using jquery load
  2. using iframe

I tried both of them and couldn't load easily. This is for load google.com and it's not working.

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

But when I try to load w3schools.com it loads into the 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>

When using jQuery load it doesn't work either.

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

And in the firebug bar shows this with " GET http://www.google.com 302 Found 291ms "

Some body help me to get rid of this.

Use jquery load to display content in a div. There is no src for a div.

Affect the src for an iframe tells your browser to fetch the content and display it in the iframe.

The proper syntax for load() would be:

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

and

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

By the way, google.com doesn't like to be loaded from other sites so you're better off using an other example.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM