Accessing elements in the iframe
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/729577/can-javascript-access-iframe-elements-from-the-parent-page">Can javascript access iframe elements from the parent page?</a>  </p>
</blockquote>



<p>I have an iframe in my document, and I want to get (and change) some attributes in it with JQuery. This is the code:</p>

<pre><code>var iframe = $('iframe');

        $("#id").click(function() {
            var btn = iframe.contents().find('a[href*="script.php"]'); 
            alert(btn);
            for (var i=0, attrs=btn.attributes, l=attrs.length; i&lt;l; i++){
                alert(attrs.item(i).nodeName);
            }
         });
</code></pre>

<p>The first alert says "[object Object]", then I'm getting errors:</p>

<blockquote>
  <p>Unsafe JavaScript attempt to access frame with URL
  <a href="http://somedomain.ru/somescript.php" rel="nofollow">http://somedomain.ru/somescript.php</a> from frame with URL
  <a href="http://domain.wia-games.net/" rel="nofollow">http://domain.wia-games.net/</a>. Domains, protocols and ports must match.</p>
</blockquote>

<p>and</p>

<blockquote>
  <p>Uncaught TypeError: Cannot read property 'length' of undefined</p>
</blockquote>

<p>How should I solve the problem?</p>

<p>UPD.
console.log(btn):</p>

<blockquote>
  <p>[prevObject: st.fn.st.init[0], context: document, selector:
  "a[href*="script.php"]", jquery: "1.9.0", constructor: function…]
  context: #document length: 0 prevObject: st.fn.st.init[0] selector:
  "a[href*="script.php"]"
  <strong>proto</strong>: Object[0]</p>
</blockquote>
