繁体   English   中英

document.getSelection() 和 window.getSelection() 之间的区别

[英]Diff between document.getSelection() and window.getSelection()

你也可以回答这个问题吗? 如何使用 javascript document.getSelecttion() 在 html 中获取选定文本的坐标

谢谢

您收到错误消息Deprecated method document.getSelection()调用。 请改用window.getSelection() 。” 在 Firefox 中,这意味着document.getSelection()是一个已弃用的方法。

它们似乎是一样的:

https://w3c.github.io/selection-api/#dom-document-getselection

getSelection()方法
如果this具有关联的浏览上下文,则该方法必须返回与this关联的选择,否则它必须返回 null。

https://w3c.github.io/selection-api/#dom-window-getselection

getSelection()方法
该方法必须在thisWindow.document属性上调用并返回getSelection()的结果。

MDN 的编辑说它们是等价的:

https://developer.mozilla.org/en-US/docs/Web/API/Document/getSelection

您可以调用Window.getSelection() ,其工作方式与Document.getSelection()相同。

https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection

您可以调用Document.getSelection() ,其工作方式与Window.getSelection()相同。

暂无
暂无

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

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