[英]How to get selected text from iframe (working on IE)
如何從iframe獲取所選文本(在IE上運行)
以下內容將在所有主流瀏覽器中運行:
function getIframeSelectionText(iframe) {
var win, doc = iframe.contentDocument;
if (doc) {
win = doc.defaultView;
} else {
win = iframe.contentWindow;
doc = win.document;
}
if (win.getSelection) {
return win.getSelection().toString();
} else if (doc.selection && doc.selection.createRange) {
return doc.selection.createRange().text;
}
}
var iframe = document.getElementById("your_iframe");
alert( getIframeSelectionText(iframe) );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.