开发者

How to get selected text from iframe (working on IE)

How to get select开发者_StackOverflow社区ed text from iframe (working on IE)


The following will work in all major browsers:

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) );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜