Listen for mouse click and keypress events within iframe

后端 未结 1 807
悲哀的现实
悲哀的现实 2021-01-15 06:38

I would like to add some explanations to each slide of an embedded swipe.to presentation. Therefore I am trying to count the times a button within the iframe is pressed or c

1条回答
  •  时光说笑
    2021-01-15 06:59

    It is possible this way:

    //left arrow
    $(document.getElementById('frame-id').contentWindow.document).keydown(function(e){
                    if(e.keyCode == 37){
                        i--;
                    };
    });
    
    //right arrow and space bar
    $(document.getElementById('test').contentWindow.document).keydown(function(e){
                    if(e.keyCode == 32 || e.keyCode == 39){
                        i++;
                    };
    });
    

    This should be embedded within $('body iframe').load(function(){ }

    0 讨论(0)
提交回复
热议问题