Javascript window.find alternative for internet explorer?

前端 未结 2 799
攒了一身酷
攒了一身酷 2021-01-21 23:21

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 ?

2条回答
  •  野的像风
    2021-01-21 23:41

    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.

提交回复
热议问题