JS判断手机访问函数

模板网 2014-09-11

函数is_mobile()手机端返回true,PC端返回false,根据返回值来判断时候是手机端访问,然后做相应的操作。

复制代码 代码如下:
<script>
function is_mobile() {
var regex_match = /(nokia|iphone|android|motorola|^mot-|softbank|foma|docomo|kddi|up.browser|up.link|htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte-|longcos|pantech|gionee|^sie-|portalmmm|jigs browser|hiptop|^benq|haier|^lct|operas*mobi|opera*mini|320x320|240x320|176x220)/i;
var u = navigator.userAgent;
if (null == u) {return true;}
var result = regex_match.exec(u);
if (null == result) {
return false
}else {
return true
}
}
if (is_mobile()) {
var weburl=window.location.href;
weburl=weburl.replace("http://www.xxx.com","http://m.xxx.com"); 
document.location.href= weburl;
</script>

<script>
function is_mobile() {
	var regex_match = /(nokia|iphone|android|motorola|^mot-|softbank|foma|docomo|kddi|up.browser|up.link|htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte-|longcos|pantech|gionee|^sie-|portalmmm|jigs browser|hiptop|^benq|haier|^lct|operas*mobi|opera*mini|320x320|240x320|176x220)/i;
	var u = navigator.userAgent;
	if (null == u) {return true;}
		var result = regex_match.exec(u);
	if (null == result) {
		return false
	}else {
		return true
	}	
}
	if (is_mobile()) {
	var weburl=window.location.href;
	weburl=weburl.replace("http://www.xxx.com","http://m.xxx.com"); 
	document.location.href= weburl;
</script>

相关文章

  1. JS 文本框默认提示信息点击清空

    JS 文本框默认提示信息点击清空,关键的代码。 复制代码 代码如下: onfocus=if(this.value==this.defaultValue){this.value=;}; onblur=if(this.value==){this.value=this.defaultValue;} type=text 效果截图:

  2. JS手机端跳转代码

    JS手机端跳转代码,通过判断浏览器版本来判断是手机端还是PC端,然后可以做相应的操作。 能够判断IE内核,opera内核,苹果、谷歌内核,火狐内核,是否为移动终端 ,android终端或者uc浏览器,是否为iPhone或者QQHD浏览器,是否iPad,是否web应该程序,没有头

  3. 从腾讯网提取的判断手机端访问跳转代码

    从腾讯网提取的判断手机端访问跳转代码,使用了一个正则表达式来判断浏览器的navigator.userAgent标志,来确认访问终端,从而做出相应的操作。 代码简单,注释详细,容易理解。 复制代码 代码如下: script type=text/javascript if(/Android|Windows Phone|w

  4. 移动端全屏滚动插件 zepto.fullpage.js

    zepto.fullpage 是专注于移动端的 fullPag e.js ,依赖 Ze pto 。 下载地址: https://github.com/yanhaijing/zepto.fullpage 功能概述 可实现移动端的单页滚动效果,可自定义参数,提供回调接口,和公开接口。 兼容性 Ios4+ Andriod2.3+(未全部覆盖) 快速

  5. JS判断手机端跳转代码

    JS判断手机端跳转代码 复制代码 代码如下: var browser={ versions:function(){ var u = navigator.userAgent, app = navigator.appVersion; return {//移动终端浏览器版本信息 trident: u.indexOf(Trident) -1, //IE内核 Opera: u.indexOf(Opera) -1, //ope

随机推荐

  1. JS 文本框默认提示信息点击清空

    JS 文本框默认提示信息点击清空,关键的代码。 复制代码 代码如下: onfocus=if(this.value==this.defaultValue){this.value=;}; onblur=if(this.value==){this.value=this.defaultValue;} type=text 效果截图:

  2. JS手机端跳转代码

    JS手机端跳转代码,通过判断浏览器版本来判断是手机端还是PC端,然后可以做相应的操作。 能够判断IE内核,opera内核,苹果、谷歌内核,火狐内核,是否为移动终端 ,android终端或者uc浏览器,是否为iPhone或者QQHD浏览器,是否iPad,是否web应该程序,没有头

  3. 从腾讯网提取的判断手机端访问跳转代码

    从腾讯网提取的判断手机端访问跳转代码,使用了一个正则表达式来判断浏览器的navigator.userAgent标志,来确认访问终端,从而做出相应的操作。 代码简单,注释详细,容易理解。 复制代码 代码如下: script type=text/javascript if(/Android|Windows Phone|w

  4. 移动端全屏滚动插件 zepto.fullpage.js

    zepto.fullpage 是专注于移动端的 fullPag e.js ,依赖 Ze pto 。 下载地址: https://github.com/yanhaijing/zepto.fullpage 功能概述 可实现移动端的单页滚动效果,可自定义参数,提供回调接口,和公开接口。 兼容性 Ios4+ Andriod2.3+(未全部覆盖) 快速

  5. JS判断手机端跳转代码

    JS判断手机端跳转代码 复制代码 代码如下: var browser={ versions:function(){ var u = navigator.userAgent, app = navigator.appVersion; return {//移动终端浏览器版本信息 trident: u.indexOf(Trident) -1, //IE内核 Opera: u.indexOf(Opera) -1, //ope