标签:function oat list phone cto script rtm lis sel
<script>
function calculatescale() {
var phoneWidth = parseInt(window.screen.width);
var phoneScale = phoneWidth / 1280;//除以的值按手机的物理分辨率
var ua = navigator.userAgent;
var viewportmetacontent = "";
if (/Android (\d+\.\d+)/.test(ua)) {
var version = parseFloat(RegExp.$1);
if (version > 2.3) { // andriod 2.3以上
viewportmetacontent=‘width=device-width,initial-scale=‘ + phoneScale + ‘,minimum-scale=‘ + phoneScale + ‘,user-scalable=yes‘;
} else {
viewportmetacontent=‘width=device-width,user-scalable=yes‘;
}
// 其他系统
} else {
viewportmetacontent = ‘width=device-width, initial-scale=‘ + phoneScale + ‘,minimum-scale=‘ + phoneScale + ‘,user-scalable=yes‘;
}
return viewportmetacontent;
}
document.write(‘<meta name="viewport" content="‘+calculatescale()+‘">‘);
</script>
window.addEventListener(‘orientationchange‘, function (event) {
var viewportmeta = document.querySelector(‘meta[name="viewport"]‘);
if (viewportmeta) {
viewportmeta.content = calculatescale();
}
});
标签:function oat list phone cto script rtm lis sel
原文地址:https://www.cnblogs.com/cathyxiao/p/9151704.html