第二步:代码实现

<script type="text/javascript"> 

  

       function get_browser() { 

           var N = navigator.appName, ua =navigator.userAgent, tem; 

           var M =ua.match(/(opera|chrome|safari|firefox|msie)\/?\s*(\.?\d+(\.\d+)*)/i); 

           if (M && (TEM = ua.match(/version\/([\.\d]+)/i)) != null) M[2] =tem[1]; 

           M = M ? [M[1], M[2]] : [N, navigator.appVersion, '-?']; 

           return M[0]; 

       } 

       function get_browser_version() { 

           var N = navigator.appName, ua = navigator.userAgent, tem; 

           var M = ua.match(/(opera|chrome|safari|firefox|msie)\/?\s*(\.?\d+(\.\d+)*)/i); 

           if (M && (tem = ua.match(/version\/([\.\d]+)/i)) != null) M[2] =tem[1]; 

           M = M ? [M[1], M[2]] : [N, navigator.appVersion, '-?']; 

           return M[1]; 

       } 

       var browser = get_browser(); 

       var browser_version = get_browser_version(); 

       var br_detect = 0; //default to run 

       if (browser == 'MSIE') { 

           if (parseInt(browser_version) < 9) { 

                var br_detect = 1; //not runthe status js 

           } 

        } //end if browser 

  

                   //setJS controller variable for speed monitor plugin 

                   varBoomRunMark = 0; //0 = enable ,  1=disable 

                   varBoomKickStartMark = 5; // run the collect plugin when random num < 5 

                   varRandomNumber = Math.floor((Math.random() * 10) + 1); 

                   if(br_detect == 0) { 

                            imgLoadBeginTime= new Date(); 

                            

                   } 

                   //console.log('randomnumber :'+ RandomNumber); 

       if (br_detect == 0) { 

                     if (BoomRunMark == 0){  

                            if(RandomNumber  < BoomKickStartMark ){ 

                                     BOOMR.init({ 

                                               beacon_url:"http://perf.che168.com/pv_perf.php", 

                                               BW:{ enabled: false }, 

                                               RT:{ 

                                                        cookie:'CHE168-RT'

                                               } 

                                     }); 

                            }//endRandomNumber check 

                     }// end BoomRunMark check 

       }//end if br_detect 

         

</script>