search page function for internet explorer

后端 未结 1 1282
渐次进展
渐次进展 2020-12-22 07:24

I need to put a search page function in the site that I\'m working on. I found one online and it works great in Firefox and Chrome but not at all in IE. I think the fact t

相关标签:
1条回答
  • 2020-12-22 08:01

    Here's a version dapted from another answer of mine.

    Demo: http://jsfiddle.net/MRp2G/5/

    Code:

    function doSearch(text) {
        var sel;
        if (window.find && window.getSelection) {
            sel = window.getSelection();
            if (sel.rangeCount > 0) {
                sel.collapseToEnd();
            }
            window.find(text);
        } else if (document.selection && document.body.createTextRange) {
            sel = document.selection;
            var textRange;
            if (sel.type == "Text") {
                textRange = sel.createRange();
                textRange.collapse(false);
            } else {
                textRange = document.body.createTextRange();
                textRange.collapse(true);
            }
            if (textRange.findText(text)) {
                textRange.select();
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题