如何做到当用户将移动设备变为横向时刷新网页 [英] How to do Refresh a web page when user turns mobile to landscape
本文介绍了如何做到当用户将移动设备变为横向时刷新网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为android和iPhone做一个web应用程序。我的问题是,我想刷新网页,当用户去风景。由于我是JavaScript的初学者,我不知道该怎么做。请帮助我
I am doing a web application for android and iPhone. My problem is, i want to do refresh the webpage, when user goes to landscape. Since i'm a beginner in javascript i don't know how to do this. please help me
推荐答案
您可以使用 orientationchange jQuery Mobile event然后做一个
You could use the orientationchange jQuery Mobile event and then do a
window.location.reload();
刷新页面。
例如:
For example:
$(function(){
// Set Inital orientation
// get the initial orientation from window which
// returns 0 for portrait and 1 for landscape
if(window.orientation == 0){
var ori = "portrait";
}else{
var ori = "landscape";
}
changeOrientation(ori);
// Orientation Change
// When orientation changes event is triggered
// exposing an orientation property of either
// landscape or portrait
$('body').bind('orientationchange',function(event){
changeOrientation(event.orientation)
})
// Change the style dependengt on orientation
function changeOrientation(ori){
// Remove all classes separated by spaces
$("#orientation").removeClass('portrait landscape');
$("#orientation").addClass(ori);
$("#orientation").html("<p>"+ori.toUpperCase()+"</p>");
}
});
这篇关于如何做到当用户将移动设备变为横向时刷新网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文