上代码:
//当手机旋转的时候,触发“orientationchange”该事件
window.addEventListener("orientationchange", hengshuping, false);
function hengshuping() {
//横屏
if (window.orientation == 90 || window.orientation == -90) {
var fromShu=window.localStorage.getItem('name')
if(fromShu=='a'){
window.location.reload(true);
window.localStorage.setItem('name','b');
}
return false;
}
//竖屏
else if (window.orientation == 0 || window.orientation == 180) {
var fromHeng = window.localStorage.getItem('name');
if(fromHeng === 'b'){
window.location.reload(true);
}
window.localStorage.setItem('name','a');
return false;
}
}