0

I want to click a button on iframe window security checkout using JavaScript .

In normal window (except iframe) we use,

document.getElementById("ButtonId").click()

But In iframe window this case is not working fine. As I think this is a security check out which is restricting me to achieve this task.

I have done the following Steps:

document.getElementById("Buttonid").click()
window.frames["frameId"].document.getElementById("Buttonid").click()

I am getting this error:

window.frames['frameId'].document is undefined

Cerbrus
  • 70,800
  • 18
  • 132
  • 147
  • 4
    Short answer: You can't if this iframe is on different domain. – antyrat Sep 26 '14 at 13:42
  • ... and [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Same_origin_policy_for_JavaScript) explains why. – Teemu Sep 26 '14 at 13:46
  • Is the URL in the iframe on the same domain as the main page? – Scott Sep 26 '14 at 13:49
  • yes URL in iframe is in different domain, then how can we do it? – Deepika Mohadikar Sep 26 '14 at 15:16
  • @DeepikaMohadikar antyrat has answered the question already. However, if you can control the page in iframe, you can use methods represented at [this SO post](http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy). – Teemu Sep 26 '14 at 15:57
  • yeah!!! This issue is resolved .. while invoking browser just add this flag.. chromium-browser --disable-web-security.. Thanks to all.. – Deepika Mohadikar Oct 30 '14 at 08:17

0 Answers0