admin管理员组文章数量:1391811
I'm trying to alert mobile device users on my site to use their devices in landscape mode. I have an alert pop up but it seems to be getting caught in an infinite loop. How would I go about stopping that loop after the user has clicked ok?
Here is the code:
window.ondeviceorientation = detectIPadOrientation;
function detectIPadOrientation ()
{
if ( orientation == 0 || orientation == 180 ){
alert ('Please use your iPad in landscape mode');
}
}
I'm trying to alert mobile device users on my site to use their devices in landscape mode. I have an alert pop up but it seems to be getting caught in an infinite loop. How would I go about stopping that loop after the user has clicked ok?
Here is the code:
window.ondeviceorientation = detectIPadOrientation;
function detectIPadOrientation ()
{
if ( orientation == 0 || orientation == 180 ){
alert ('Please use your iPad in landscape mode');
}
}
Share
Improve this question
edited May 20, 2013 at 16:02
Pointy
414k62 gold badges595 silver badges629 bronze badges
asked May 20, 2013 at 15:58
Allan MoodyAllan Moody
311 gold badge1 silver badge5 bronze badges
3
- 2 FWIW, telling people what to do with their device isn't exactly a UX "best practice." – Pointy Commented May 20, 2013 at 16:03
- It's only for a specific page not for the entire site. @Pointy – Allan Moody Commented May 20, 2013 at 16:08
-
Perhaps this has to do with how quickly iOS rechecks screen position - over and over I presume. You could set a flag that would ensure it only pops up one time.
var pop=true;
if(orientation... && pop){alert(...); pop=false};}
– rGil Commented May 20, 2013 at 16:11
2 Answers
Reset to default 2The following code will send an alert based on screen orientation. The alert will only be sent if the screen is in landscape mode.
window.onload = function() {
if ( window.orientation == 0 || window.orientation == 180 ) {
alert ('Please use your mobile device in landscape mode');
}
};
You can make the website alert users who are using a mobile device, not just when the device is in landscape.
This question will probably help you out.
Or, the answer to your exact question might be on this duplicate question.
You may also try identifying the the user with
var isiPad = navigator.userAgent.match(/iPad/i) != null;
And sending him an alert if this does not equal NULL
I hope this helped you out.
本文标签: Javascript Alert on mobile devices based orientationStack Overflow
版权声明:本文标题:Javascript Alert on mobile devices based orientation - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744769773a2624267.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论