sel
sel

Reputation: 31

Javascript window.find alternative for internet explorer?

i want to implement the javascript function of window.find(). but it is not working in internet explorer. what could be an alternative for this code ?

Upvotes: 2

Views: 3943

Answers (2)

Kemal Dağ
Kemal Dağ

Reputation: 2763

To achieve browser compatibility use

function windowFind(str){
    if("find" in window){
         return window.find(str);
    }else{
         return document.getElementsByTagName("body").innerHTML.indexOf(str) > -1;
    }
}

This method is called feature detection and is used in many javascript libraries to achieve browser compatibility.

Upvotes: 2

Voonic
Voonic

Reputation: 4785

try this

function contains(strs) {
    return document.body.innerText.indexOf(strs) > -1;
}

Upvotes: 0

Related Questions