2016-11-08 39 views
1

在Chrome中,我可以使用如何获取选定的文本?

window.getSelection().toString() 

获取所选文本。但是,即使Mozilla开发者网络says it should work,在Firefox中,这不会给出选定的文本,而是文字字符串Instance of 'Selection'

获取选定文本的正确方法是什么?

+1

好像它是由飞镖游戏默认的'的toString()'实现覆盖。那么'window.getSelection()。getRangAt(0)'? –

+0

@GünterZöchbauer应该提到我也尝试过,类似的结果。 –

+0

“相似的结果”究竟意味着什么? –

回答

2

这看起来非常像dart:html中的一个错误。

至于解决方法,你可以使用JS-互操作

DartPad example

import 'dart:js'; 
... 
print(context.callMethod('getSelection')); 
1

Dart2JS确实是罪魁祸首。谈到微小关闭,查看输出的Javascript显示:

t2 = J.getInterceptor(selection); 
t1 = t2.toString$0(selection); 

手动编译后替换:

t1 = selection.toString(); 

修复该问题。

我已报告的错误:https://github.com/dart-lang/sdk/issues/27789

相关问题