怎么用JS编写类似Chrome里面CTRL+F功能?为什么我写的不支持?

function mySearch() {
if (isTrange) {
clearHighShow();
}

var bookmark;
var range;

if (detectMicrosoftBrowser()) {
    range = document.body.createTextRange();
    bookmark = range.getBookmark();
}else{
    range = document.createRange();
}

var key = searchFiled.getValue();

if (detectMicrosoftBrowser()) {
    range.collapse(true);
    range.moveToBookmark(bookmark);

    while (range.findText(key)) {
        var text2 = range.text.replace(range.text, "<span class='hsp' >" + range.text + "</span>");
        range.pasteHTML(text2);
        isTrange = true;
        range.scrollIntoView();
    }

} else {
    var s = window.getSelection();

    s.collapse(document.body, 0);

    while (window.find(key)) {
        var span_tag = document.createElement("SPAN");
        span_tag.className = "hsp";

        s.getRangeAt(0).surroundContents(span_tag);
        isTrange = true;
    }
    document.documentElement.scrollTop = 0;
}

}

在chrome里面s.collapse(document.body, 0);拿不到值,是方法不对吗?
如果要做到每个关键字跳转该怎么写?

https://zhidao.baidu.com/question/138984783946717965.html