2013-01-08 60 views
1

這可能是常見的問題。我看到了這個問題的幾個答案。加載網絡鏈接到div或iframe

  1. 使用iframe的

我想他們兩個,不能輕鬆地將使用jQuery負載

  • 。 這是用於加載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

    一些身體幫我擺脫這一點。

  • +0

    你想做什麼? – Chanckjh

    +0

    @Chanckjh:原諒錯別字,不是每個人都寫好英文 – JFK

    +0

    我想這是這個的重複:http://stackoverflow.com/questions/8524449/google-homepage-will-not-load-in-an- iframe – Chanckjh

    回答

    0

    使用jquery load顯示div中的內容。有一個div沒有src

    影響srciframe告訴您的瀏覽器獲取內容並將其顯示在iframe中。

    load()正確的語法是:

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

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

    順便說一句,google.com不喜歡從其他網站加載的,所以你會更好使用另一個例子。