user2572943
user2572943

Reputation: 155

Access anchor tag attribute inside iframe

Parent domain: www.parent.com Iframe domain: www.iframe.com

<html>
  <head></head>
  <body>
  <iframe id="trick" src="www.iframe.com/test">
    <html>
      <head></head>
      <body>
        <a href="www.test.com">test</a>  
      </body>
    </html>
  </body>
</html>

Question: how to access the value of href of anchor tag inside iframe using jquery?

Upvotes: 0

Views: 1295

Answers (2)

javitube
javitube

Reputation: 101

Check this link: http://simple.procoding.net/2008/03/21/how-to-access-iframe-in-jquery/

$('#iframeID').contents().find('#someID').html();

Upvotes: 0

Quentin
Quentin

Reputation: 943585

Since they pages appear on different origins:

  1. The page containing the frame needs to listen for a Message event.
  2. The page inside the frame needs to send a message using postMessage.

This, obviously, requires changes on both sites. Explicit co-operation between the sites is required for obvious security reasons (if they aren't obvious, imagine your bank's website being loaded in an iframe by a random site you visited via Google).

Upvotes: 1

Related Questions