简体   繁体   English

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

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

Also can you please answer this question?你也可以回答这个问题吗? how do I get co-ordinates of selected text in an html using javascript document.getSelecttion() 如何使用 javascript document.getSelecttion() 在 html 中获取选定文本的坐标

thanks谢谢

You get error message Deprecated method document.getSelection() called.您收到错误消息Deprecated method document.getSelection()调用。 Please use window.getSelection() instead." in Firefox which means document.getSelection() is a deprecated method.请改用window.getSelection() 。” 在 Firefox 中,这意味着document.getSelection()是一个已弃用的方法。

They seem to be the same:它们似乎是一样的:

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

getSelection() method getSelection()方法
The method must return the selection associated with this if this has an associated browsing context, and it must return null otherwise.如果this具有关联的浏览上下文,则该方法必须返回与this关联的选择,否则它必须返回 null。

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

getSelection() method getSelection()方法
The method must invoke and return the result of getSelection() on this 's Window.document attribute.该方法必须在thisWindow.document属性上调用并返回getSelection()的结果。

Editors of MDN say they're equivalent: MDN 的编辑说它们是等价的:

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

You can call Window.getSelection() , which works identically to Document.getSelection() .您可以调用Window.getSelection() ,其工作方式与Document.getSelection()相同。

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

You can call Document.getSelection() , which works identically to Window.getSelection() .您可以调用Document.getSelection() ,其工作方式与Window.getSelection()相同。

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

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