Define an event on iFrame element with jQuery

后端 未结 6 2053
Happy的楠姐
Happy的楠姐 2020-12-18 09:19

I try to define a live event on img tags store on a iFrame. For example, I would like obtain a simple javascript alert box when I click a image on my iFrame.

Do you

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-18 09:54

     $("iframe").contents().find("img")
    

    This will target images within the iFrame. But be aware that jquery will only traverse the iFrame if it is not a violation of the browser's (or jquery's) cross-site policy.

    That means if the iframe is google.com, you can't touch the inner DOM.

提交回复
热议问题