During string search using window.find() a dialog box appear

1.3k views Asked by At

I am trying to search string and highlight those string. But during search a find dialog box appear. How can I disable the find dialog box ? Here is my code -->

function doSearch(text) {
    if (window.find && window.getSelection) {
        document.designMode = "on";
        var sel = window.getSelection();
        sel.collapse(document.body, 0);

        while (window.find(text)) {
            document.execCommand("HiliteColor", false, "yellow");
            sel.collapseToEnd();
        }
        document.designMode = "off";
    } else if (document.body.createTextRange) {
        var textRange = document.body.createTextRange();
        while (textRange.findText(text)) {
            textRange.execCommand("BackColor", false, "yellow");
            textRange.collapse(false);
        }
    }
}
1

There are 1 answers

0
JackArbiter On

Firefox has a bug wherein it will display the find dialog box with window.find() if it has a blank argument:

https://bugzilla.mozilla.org/show_bug.cgi?id=672395

So if anyone is having this problem, you likely need to check the argument you're sending to window.find().