gpt4 book ai didi

javascript - 如何从 iframe 中获取选定的文本(在 IE 上工作)

转载 作者:行者123 更新时间:2023-11-30 13:38:23 26 4
gpt4 key购买 nike

如何从 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) );

关于javascript - 如何从 iframe 中获取选定的文本(在 IE 上工作),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3614929/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com