Get selected text on IPad 2 with Javascript

可紊 提交于 2019-12-06 10:52:50

Okay finally I've solved the problem: As Tim assumed the click events causes to selection to collapse. I consider this as rather strange behavior as on regular Safari this does not happen.

However, the solution is not to use the click event. Instead of I'm using "vlick" provided by the jquery mobile.

Full working example:

<!DOCTYPE html> 
<html> 
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" />
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
    <script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script>
</head>
<body> 
    Hello World! <input type="button"  id="button1" /> 

    <script> 
        function a()  
        { 
            alert(window.getSelection()); 
        } 

        $("#button1").bind("vclick",a);
    </script>       
</body> 
</html> 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!