1

I want jquery or javascript to access DOM in Iframe.

For example, I make a iframe to show amazon. then I wanna get a banner image link on amazon. Can I do this?

and I have one more problem. if I click amazon banner that is made a by _blank target on "a" Tag in a iframe, browser make a new tab. but I wanna see a new page in a iframe.

Pedram
  • 15,766
  • 10
  • 44
  • 73
EddyKim
  • 155
  • 1
  • 14
  • To open a link in an iframe, use the name of an existing iframe as the target instead of "_blank". – Teemu Nov 25 '17 at 08:24
  • Possible duplicate of [How to access the content of an iframe with jQuery?](https://stackoverflow.com/questions/1796619/how-to-access-the-content-of-an-iframe-with-jquery). But the page and iframe content should be from same domain. – Alexander Nov 25 '17 at 08:44
  • @Alexander More relevant dupe would then be: https://stackoverflow.com/questions/364952/jquery-javascript-accessing-contents-of-an-iframe – A. Wolff Nov 25 '17 at 08:46
  • 1
    @A.Wolff , I was adding similar comment to my flag.. :) – Alexander Nov 25 '17 at 08:50

1 Answers1

2

You cannot do that if the origin of the iframe is different from the parent document : https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy

ggirodda
  • 770
  • 7
  • 19
  • 1
    As a side node, it is possible in some cases athought that implies the iframed page needs to expose [window.postMessage()](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage). Anyway your answer regarding amazon is correct! – A. Wolff Nov 25 '17 at 08:40
  • Thank you for your answer. and I just decided to use request module. and show using echo html source on child page. – EddyKim Nov 26 '17 at 04:03