[英]redirect desktop users to another page and mobile user to the main page
I have a problem with this code.I want to redirect my desktop users to block.php page and dont let them in. 我有这个代码的问题。我想将我的桌面用户重定向到block.php页面,不要让他们进入。
i tested a lot of code and non of them work for me. 我测试了很多代码,但没有为我工作。
at the moment,i found this code.its works perfectly...but there is e tiny problem. 此刻,我发现这个代码。它运作完美......但是存在一个小问题。
when i check my site with mobile ( ios device )..it keeps reloading 当我用手机(ios设备)检查我的网站..它不断重新加载
this is the code : 这是代码:
<script> if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPod/i)) { window.location.assign("http://example.com"); } else { window.location.assign("http://example.com/block.php"); } </script>
what is the problem? 问题是什么?
Assuming this script is running on http://example.com , calling window.location.assign inside of the if block would reload the page. 假设此脚本在http://example.com上运行,则在if块内调用window.location.assign将重新加载页面。 It seems to me like you want to call window.location.assign(' http://example.com/block.php ') only if the user is NOT on a mobile device.
在我看来,只有当用户不在移动设备上时才想要调用window.location.assign(' http://example.com/block.php ')。
You could try something like this: 你可以尝试这样的事情:
function checkIsMobile () { if(navigator.userAgent.match(/iPhone/i)){ return true; } else if (navigator.userAgent.match(/iPad/i)){ return true; } else if (navigator.userAgent.match(/iPod/i)){ return true; } else { return false; } } if (!checkIsMobile()) { window.location.assign("http://example.com/block.php"); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.