我有一个测试,我去Google.com并在控制台中运行以下命令:
test = document.querySelector('#lst-ib') //#lst-ib is the ID of Google's search bar
test.value = 'abcd'
test.select()
window.getSelection().toString() //expected return value of 'abcd'
如果我在Chrome或Safari中运行此测试,我会得到预期的返回值' abcd' - 表示已选择输入中的文本。
在FireFox中,我得到一个空字符串。
有没有人有解释?当我从脚本而不是控制台在我自己的页面上运行此代码时,我会得到相同的行为。
我正在使用Firefox 54.01和Chrome 59.0.3071.115
进行测试