Does Safari handle the paste event correctly?

前端 未结 2 1028
梦谈多话
梦谈多话 2021-01-04 14:21

I\'m trying to write some code for Safari for handling the \'paste\' event, but it doesn\'t seem to work right. According to the WebKit DOM reference, oncut, <

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-04 14:50

    Don't know if it helps you, but I use a out-of-screen input to force safari accept paste on the page. It helped me so here it goes:

    I'm doing:

    script:

    $(document).bind('paste', function(e) {
        var data = e.originalEvent.clipboardData.getData('Text');
        // here using data from clipboard
    });
    
    $(function(){
       $('input.special').focus();
    });
    

    css:

    input.special{
    position:absolute;
    top:-40px;
    }
    

    html:

    
    

提交回复
热议问题