2011-10-23 65 views
1

http://api.jquery.com/contents/通过访问一个iframe的内容没有成功“内容()”

据说,您可以通过内容访问一个I帧DOM()方法。 我剪切并粘贴了代码,将id添加到了我的页面上的iframe,然后去了一个非常简单的div,它是iframe中唯一的div。它没有找到它。我已经成功地设法操纵iframe本身的CSS,所以我很确定一切都是正确的。 这也是所有文件准备好条件。

有问题的页面在这里http://syndex.me/tagged/belgium

希望有人能阐明这方法运作的一些情况。

感谢

$("#tumblr_controls").css({ 
    position : 'fixed', 
    top : 'auto', 
    bottom : '15px', 
}); //works 
$("#tumblr_controls").contents().find("div").css("right","auto"); //doesnt work 
$("#tumblr_controls").contents().find("div").css("left","0"); //doesnt work 

请注意,您必须登录到tumblr才能看到问题的控制,我相信。

<iframe src="http://assets.tumblr.com/iframe.html?10&amp;src=http%3A%2F%2Fsyndex.me%2F&amp;lang=en_US&amp;name=syndex&amp;brag=0" scrolling="no" width="330" height="25" frameborder="0" style="right: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; background-color: transparent; overflow-x: hidden; overflow-y: hidden; position: fixed; top: auto; bottom: 15px; z-index: 1000007; " id="tumblr_controls"> 

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
    <head> 
     <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
     <meta http-equiv="x-dns-prefetch-control" content="off"> 
     <link rel="icon" href="http://assets.tumblr.com/images/favicon.gif?2" type="image/gif"> 
</head> 
    <body style="background-color:transparent; margin:0px; padding:0px;" onload="var image1 = new Image(); image1.src = 'http://assets.tumblr.com/images/iframe_like_alpha.png'; 
    var image2 = new Image(); image2.src = 'http://assets.tumblr.com/images/iframe_like_active_alpha.png';"> 

    <style> 
     img { 
      margin-left: 3px; 
     } 
    </style> 

    <div style="position:absolute; top:3px; right:3px; white-space:nowrap; height:20px;"> 

<form action="/follow" method="post" style="display:block; float:left;" onsubmit="_gaq.push(['_trackEvent', 'Iframe', 'Follow', 'syndex');"> 
          <input type="hidden" name="form_key" value="4d9WHkMln7qxbqRkkU1FJ51jYk"> 
          <input type="hidden" name="id" value="syndex"> 
          <input type="image" src="http://assets.tumblr.com/images/iframe_follow_alpha.png?663" style="width:58px; height:20px; border-width:0px; display:block; 
          margin-left:3px; cursor:pointer;" alt="Follow"> 
         </form> 

      <a target="_top" href="http://www.tumblr.com/dashboard"><img src="http://assets.tumblr.com/images/iframe_dashboard_alpha.png?663" alt="Dashboard" style="height:20px; 
      width:81px; border-width:0px; display:block; float:left; cursor:pointer;"></a> 

         </div> 

</body></html> 

</iframe> 
+0

请在问题你的代码。 ':)' –

回答

3

您没有权限访问tumblr_controls框架的内容,因为它来自另一个域。

进一步信息:

+0

这将是一个很好的理由。有人想要添加一些内容到你的答案,顺便说一句。 –

+0

因此是一个考虑不同域名的子域名?另外,我在syndex.me上,但它都是tumblr。如果我去syndex.tumblr.com它会工作吗?尽管去那里会自动将我重新路由到syndexme。 – RGBK

+0

为什么它不会在控制台中抛出错误呢?似乎不寻常。 – RGBK