简体   繁体   English

为什么 window.getSelection() 在 firefox 和 chrome 之间是不同的?

[英]Why window.getSelection () is different between firefox and chrome?

with:和:

<div contenteditable="true"> ... text.... <img src="image.png" height="50" width="50" onmouseup="alert(window.getSelection().isCollapsed)"> ... text... </div>

if I click (mouseup on img) in firefox alert says: 'false', in chrome alert says: 'true'.如果我在 firefox 中单击(img 上的鼠标),警报会显示:'false',在 chrome 警报中会显示:'true'。 Why are different?为什么不同? (Firefox seems to indicate that there is selected text) (Firefox 好像提示有选中的文字)

with:和:

<div contenteditable="true"> ... text.... <img src="image.png" alt="hello" height="50" width="50" onmouseup="alert(window.getSelection().toString())"> ... text... </div>

if I click (mouseup on img) in firefox alert says: 'hello', in chrome alert says: ''.如果我在 firefox 中单击(img 上的鼠标),警报会显示:'你好',在 chrome 警报中会显示:''。 Why does Firefox say I've selected the 'hello' text?为什么 Firefox 说我选择了“你好”文本? Firefox wrong and chrome no? Firefox 错了,chrome 没有?

The document/window.getSelection method works differently in Google Chrome, Safari and Internet Explorer than in Firefox and Opera. document/window.getSelection方法在Google Chrome,Safari和Internet Explorer中的工作方式与在Firefox和Opera中的不同。 It returns a string in Firefox and Opera, and returns a selectionRange object in Google Chrome, Safari and Internet Explorer (the document.getSelection method is identical to the window.getSelection method in Google Chrome, Safari and Internet Explorer). 它在Firefox和Opera中返回一个字符串,并在Google Chrome,Safari和Internet Explorer中返回selectionRange对象(document.getSelection方法与Google Chrome,Safari和Internet Explorer中的window.getSelection方法相同)。 Because of that, this method should not be used. 因此,不应使用此方法。

It is a known bug in firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=1417535这是 firefox 中的一个已知错误: https://bugzilla.mozilla.org/show_bug.cgi?id=1417535

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM