Home  >  Article  >  Web Front-end  >  Detailed explanation of examples of js judging browser and hack scroll bars

Detailed explanation of examples of js judging browser and hack scroll bars

零下一度
零下一度Original
2017-07-24 14:48:331414browse

This article mainly introduces how to write JavaScript to judge browsers and hack scroll bars. Friends who need it can refer to it

I am bored today and help a netizen solve a very boring problem. Use JS to judge whether the page is A scroll bar appears. I read some codes on the Internet, but after verification, it does not work. The following is the code I searched on the Internet:

When the visible area is smaller than the actual height of the page, it is determined that the scroll bar appears

Determine the core of major browsers:


var userAgent = navigator.userAgent;                              //取得浏览器的userAgent字符串 
  var isOpera = userAgent.indexOf("Opera") > -1;                         //判断是否Opera浏览器 
  var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1 && !isOpera; //判断是否IE浏览器 
  var isEdge = userAgent.indexOf("Edge") > -1 && !isIE;                     //判断是否IE的Edge
  var?isFF?=?userAgent.indexOf("Firefox")>-1                           //判断是否Firefox浏览器??
  var?isSafari?=?userAgent.indexOf("Safari")>-1&&?userAgent.indexOf("Chrome")==-1;        //判断是否Safari浏览器??
  var?isChrome?=?userAgent.indexOf("Chrome")>-1&&?userAgent.indexOf("Edge")==-1;         //判断Chrome浏览器??

Process each browser scroll bar. The following is how I write the scroll bar in the hidden company project, FYI:


if(isFF){
    console.log('火狐')
    $('#parent').width((windowWidth -320)*(1.01749));
  }else if(isChrome){ 
    console.log('谷歌')
    $('#parent').width((windowWidth -320)*(1.01749));
  }else if(isIE){ 
    console.log('ie10-ie5')
    $('#parent').width((windowWidth -320)*(1.01720));
  }else if(isEdge){
    console.log('edge')
    $('#parent').width((windowWidth -320)*(1.02224));
  }else{
    console.log('ie11和其他浏览器')
    $('#parent').width((windowWidth -320)*(1.01816));
  }

The above is the detailed content of Detailed explanation of examples of js judging browser and hack scroll bars. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn