码迷,mamicode.com
首页 > 移动开发 > 详细

实现网页只能移动端访问PC不可访问

时间:2018-05-18 13:58:16      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:return   map   脚本   script   direct   and   org   自己   useragent   


第一种:直接JS脚本

<script type="text/javascript">
try {
var urlhash = window.location.hash;
if (!urlhash.match("fromapp"))
{
if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i)))
{
window.location="http://www.laozuo.org(更换成自己的WAP网站)";
}
}
}
catch(err)
{
}</script>

第二种,稍微长一些,引用

function uaredirect(murl){
try {
if(document.getElementById("bdmark") != null){
return;
}
var urlhash = window.location.hash;
if (!urlhash.match("fromapp")){
if ((navigator.userAgent.match(/(iPhone|iPod|Android|ios|iPad)/i))) {
location.replace(murl);
}
}
} catch(err){}
}

上述的脚本保持到mobile.js文件,然后在需要调用的页面引用下面2个JS调用文件。

<script src="mobile.js" type="text/javascript"></script>
<script type="text/javascript">uaredirect("http://www.laozuo.org(更换成自己的WAP网站)");</script>

 

实现网页只能移动端访问PC不可访问

标签:return   map   脚本   script   direct   and   org   自己   useragent   

原文地址:https://www.cnblogs.com/sucks/p/9055496.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!