Question

I am trying to create a click event on an iframe:

This is what I'm trying but without success:

$('iframe').contents().find('#theButton').click();

What I'm I doing wrong here?

Was it helpful?

Solution

As a security principle; You are not allowed to do anything in an iframe that's base uri is different from what is in the address bar; You just allowed to manipulate the iframe'e that's src tag is equal to page's.

Think about what would be happen if you insert a bank's internet banking in an iframe and cheate the people and in backend change the source of money transfers to your own account :D

but what you can do is to get the html source code of the where you want to show in an iframe; and show it using javascript; then you will be able to treat with that source code like your own.

OTHER TIPS

try in this way it will work for u

 $('iframe').load(function(){

    var iframe = $('iframe').contents();

    iframe.find("div").click();
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top