//sweet hack to set meta viewport for desktop sites squeezing down to mobile that are big and have a fixed width//first see if they have window.screen.width avail(function() {if (window.screen.width){var setViewport = {//smaller devicesphone: 'width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no',//bigger ones, be sure to set width to the needed and likely hardcoded width of your site at large breakpointsother: 'width=1045,user-scalable=yes',//current browser widthwidthDevice: window.screen.width,//your css breakpoint for mobile, etc. non-mobile firstwidthMin: 560,//add the tag based on above vars and environmentsetMeta: function () {var params = (this.widthDevice <= this.widthMin) ? this.phone : this.other;var head = document.getElementsByTagName("head")[0];var viewport = document.createElement('meta');viewport.setAttribute('name','viewport');viewport.setAttribute('content',params);head.appendChild(viewport);}}//call itsetViewport.setMeta();}}).call(this);
function getViewportSize(w) {
// Use the specified window or the current window if no argumentw = w || window;
// This works for all browsers except IE8 and beforeif (w.innerWidth != null) return { w: w.innerWidth, h: w.innerHeight };
// For IE (or any browser) in Standards modevar d = w.document;if (document.compatMode == "CSS1Compat")return { w: d.documentElement.clientWidth,h: d.documentElement.clientHeight };
// For browsers in Quirks modereturn { w: d.body.clientWidth, h: d.body.clientHeight };
}
<script>$(document).ready(function(){if(window.matchMedia("(max-width: 767px)").matches){// The viewport is less than 768 pixels widealert("This is a mobile device.");} else{// The viewport is at least 768 pixels widealert("This is a tablet or desktop.");}});</script>