addEventListener to iFrame

后端 未结 4 1479
北海茫月
北海茫月 2020-12-18 03:33

I\'m tryin to add event listener to mouseup inside iframe object:

$(\"#myIFrame\").contents().find(\"body\").bind(\"mouseup\", function() {
    //e.preventDe         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-18 04:21

    If you just want a plain vanilla Javascript way, you can use the following:

    var iframe = document.getElementById('myIFrame');
    iframe.contentDocument.body.addEventListener('mouseup', Handler);
    
    function Handler() {
        alert('works');
    }
    

提交回复
热议问题