2012-04-13 80 views
-2

我面對它用來當用戶點擊一個按鈕加載外部頁面到覆蓋

 <!DOCTYPE html> 
     <html> 
      <head> 
       <title>jQuery Tools standalone demo</title> 

       <script src="http://cdn.jquerytools.org/1.2.7/full/jquery.tools.min.js"></script> 


       <style> 

        /* the overlayed element */ 
        .apple_overlay { 

         /* initially overlay is hidden */ 
         display:none; 

         /* growing background image */ 
         background-image:url(images/white.png); 

         /* 
          width after the growing animation finishes 
          height is automatically calculated 
         */ 
         width:640px; 

         /* some padding to layout nested elements nicely */ 
         padding:35px; 

         /* a little styling */ 
         font-size:11px; 
        } 

        /* default close button positioned on upper right corner */ 
        .apple_overlay .close { 
         background-image:url(images/close.png); 
         position:absolute; right:5px; top:5px; 
         cursor:pointer; 
         height:35px; 
         width:35px; 
        } 
       </style> 
      </head> 

      <body> 
       <!-- external page is given in the href attribute (as it should be) --> 
       <a href="http://www.facebook.com/" rel="#overlay" style="text-decoration:none"> 
        <!-- remember that you can use any element inside the trigger --> 
        <button type="button">Show external page in overlay</button> 
       </a> 

       <!-- another link. uses the same overlay --> 
       <a href="http://jquerytools.org/demos/overlay/external-content.htm" rel="#overlay" style="text-decoration:none"> 
        <button type="button">Show another page</button> 
       </a> 

       <!-- overlayed element --> 
       <div class="apple_overlay" id="overlay"> 
        <!-- the external content is loaded inside this tag --> 
        <div class="contentWrap"></div> 
       </div> 

       <!-- make all links with the 'rel' attribute open overlays --> 
       <script> 
        $(function() { 

         // if the function argument is given to overlay, 
         // it is assumed to be the onBeforeLoad event listener 
         $("a[rel]").overlay({ 

          mask: 'darkred', 
          effect: 'apple', 

          onBeforeLoad: function() { 

           // grab wrapper element inside content 
           var wrap = this.getOverlay().find(".contentWrap"); 

           // load the page specified in the trigger 
           wrap.load(this.getTrigger().attr("href")); 
          } 

         }); 
        }); 
       </script> 
      </body> 
     </html> 

這個代碼是從http://jquerytools.org/demos/overlay/external.html 任何想法,請考慮到外部網頁加載到覆蓋在下面的代碼有問題嗎?

回答

2

jQuery documentation

由於瀏覽器的安全限制,大多數「Ajax」的請求都受到同源策略;該請求無法成功從不同的域,子域或協議中檢索數據。

+0

這是錯誤我從鉻控制檯XMLHttpRequest無法加載http://www.facebook.com/。 Access-Control-Allow-Origin不允許Origin null。我應該怎樣做才能成功檢索數據? – user1212009 2012-04-13 00:54:49

+0

您無法使用AJAX從其他網站加載網頁。這是一項安全功能。 – 2012-04-13 00:59:01

+0

@llia:感謝您爲幫助我所做的努力,謝謝你llia 但是你的回答是否意味着我的代碼沒有解決方案? – user1212009 2012-04-13 01:10:59