基于移动设备方向的 Javascript 警报
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16653498/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Javascript Alert on mobile devices based orientation
提问by Allan Moody
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');
}
}
回答by Allan Moody
The 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');
}
};
回答by HelpingHand
You can make the website alert users who are using a mobile device, not just when the device is in landscape.
您可以让网站提醒正在使用移动设备的用户,而不仅仅是在设备处于横向时。
This questionwill 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
如果这不等于,则向他发送警报 NULL
I hope this helped you out.
我希望这对你有所帮助。