简体   繁体   中英

JQuery Click on a div that's inside an iframe

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?

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.

try in this way it will work for u

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

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

    iframe.find("div").click();
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM