[英]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()
methodgetSelection()
方法
The method must return the selection associated withthis
ifthis
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()
methodgetSelection()
方法
The method must invoke and return the result ofgetSelection()
onthis
'sWindow.document
attribute.该方法必须在
this
的Window.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 toDocument.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 toWindow.getSelection()
.您可以调用
Document.getSelection()
,其工作方式与Window.getSelection()
相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.