Javascript的Andr​​oid开选定的文本脚本 [英] Javascript-Android get selected text script

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

问题描述

我试图摆脱对Android设备的每个touchend事件的html页面选定的文本,但我没有能够得到选定的文本。

I tried to get selected text from an html page on each touchend event in android device but am not able to get selected text.

的Javascript code是:

Javascript code is :

if(window.getSelection)
{
    t = window.getSelection();
}
else if(document.getSelection)
{
    t = document.getSelection();
}
else if(document.selection)
{
    t = document.selection.createRange().text;
}

先谢谢了。

推荐答案

您在网页视图这样做呢?

Are you doing this in a webview ?

window.getSelection()返回Selection对象。你可以通过调用获取文本的toString()

window.getSelection() returns the Selection object. You can get the text by calling toString()

if( window.getSelection){
   t = window.getSelection().toString();
}

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

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