jQuery to trigger a click on an iFrame?

Your jquery image selector is wrong.

change

jQuery("input.image")

to

$("#image")

Then everything will work. You can see it in this fiddle

Post Edit

If the question is to trigger a click on one of the elements contained in the iFrame, then replace the

$("#iframe").click()

with something like:

$("#iframe").contents().find("a:first").click();

This will only work if the contents of the main page and the iFrame’s page are on the same domain. Otherwise browsers will prevent the action as it is cross site scripting. You can see in your example, XSS prevention will occur as demonstrated in this fiddle

Leave a Comment