简体   繁体   中英

How to detect desktop and mobile browsers width with maximum compataibility

So i am running media queries and this code:

 //Check different widths as different browsers report it differently
 if ($(window).width()!==0) {
     width = $(window).width();
 }
 else if (window.innerWidth!==0) {
     width = window.innerWidth;
 }

But it now appears that these are not matching up with my media queries. That combined with certain mobile aren't liking these widths means that my styles don't always match my JS added styles.

Does anybody have a complete way to detect browser width with JavaScript or jQuery?

The situation is complicated you will either need a plugin that handles all the various browser idiosyncrasies for you, or you will need to do this yourself. This article was very helpful to me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM