防止横竖屏时,iphone自动缩放的一段代码
function orientation_change() { var viewport = document.querySelector('meta[name="viewport"]'); if (window.orientation == 0 || window.orientation == 180) viewport.setAttribute("content", "width=device-width, maximum-scale=1.0, initial-scale=1.0, user-scalable=no"); else if (window.orientation == -90 || window.orientation == 90) viewport.setAttribute("content", "width=device-height, maximum-scale=1.0, initial-scale=1.0, user-scalable=no"); } window.onorientationchange = orientation_change;
思路不错,记一下。