Android开选定的触摸选择文本 [英] Android get selected text on touch selection

查看:100
本文介绍了Android开选定的触摸选择文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我就先在安卓上selection.It选定的文本不是工作在触摸设备。但它工作正常,在正常的浏览器。

I tried to get selected text in android on selection.It is not working in touch devices. But it is working fine in normal browsers.

if(!window.Kolich) {
   Kolich = {};
}
Kolich.Selector = {};
// getSelected() was borrowed from CodeToad at
// http://www.codetoad.com/javascript_get_selected_text.asp
Kolich.Selector.getSelected = function() {
   var t = '';
   if(window.getSelection) {
      t = window.getSelection();
   }
   else if(document.getSelection) {
      t = document.getSelection();
   }
   else if(document.selection){
      t =document.selection.createRange().text;
   }
   return t;
}
Kolich.Selector.mouseup = function(e){
   var st = Kolich.Selector.getSelected();
   alert(st);
}

但Android的触摸选择不工作与此code ..请帮助

But Android touch selection not working with this code.. please help

推荐答案

最近WebKit的浏览器,包括在最近的Andr​​oid版本的默认浏览器,支持 selectionchange 活动的文件节点。此事件不会在Opera或Mozilla存在(但由于5.5版本的IE浏览器已经存在)。

Recent WebKit browsers, including the default browser in recent versions of Android, support a selectionchange event on Document nodes. This event doesn't exist in Opera or Mozilla (but has existed in IE since version 5.5).

例如code:

document.onselectionchange = function() {
    alert( window.getSelection().toString() );
};

这篇关于Android开选定的触摸选择文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆