Attach click handler even on element inside iframe with jQuery

前端 未结 2 726
一生所求
一生所求 2020-12-16 14:50

How can I attach a click event handler to an element inside an iframe?

Here\'s what I tried and doesn\'t work:

$(\"#parent iframe\").contents().find(         


        
2条回答
  •  旧时难觅i
    2020-12-16 15:05

    Basically probably not as at a guess the content is likely to be from a different domain (usual use of iFrames). These articles explain why:

    iframes and cross domain security Cross-Domain Ajax Insecurity

    Alternatively you will need to modify the source code in the iFrame (if you have control over it) or you can ask users to reduce their browser security (might be possible on an intranet, but even then not a good idea).

提交回复
热议问题