admin管理员组文章数量:1356377
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
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
Share Improve this question asked Jan 13, 2012 at 9:46 FreshBitsFreshBits 1,0134 gold badges13 silver badges25 bronze badges 2- 2 There exists an question like this and an answer ;) stackoverflow./questions/850472/… – matzino Commented Jan 13, 2012 at 9:52
- please close this question to avoid duplicates – Murtaza Commented Jan 13, 2012 at 10:12
2 Answers
Reset to default 6You could use the orientationchange jQuery Mobile event and then do a
window.location.reload();
to refresh the page.
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>");
}
});
You could use a timer and periodically check:
if (window.innerHeight > window.innerWidth) {
// Redirect code, window.location...
}
本文标签: javascriptHow to do Refresh a web page when user turns mobile to landscapeStack Overflow
版权声明:本文标题:javascript - How to do Refresh a web page when user turns mobile to landscape - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743951404a2567357.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论