方法一:
<SCRIPT LANGUAGE="JavaScript">
function mobile_device_detect(url){</SCRIPT>
方法二:
需要手机端也网页的数据同步
<script type="text/javascript">
(function(){var ua=navigator.userAgent.toLowerCase();var bIsIpad=ua.match(/ipad/i)=="ipad";var bIsIphoneOs=ua.match(/iphone os/i)=="iphone os";var bIsAndroid=ua.match(/android/i)=="android";var bIsWM=ua.match(/windows mobile/i)=="windows mobile";if(bIsIpad||bIsIphoneOs||bIsAndroid||bIsWM){window.location.href="http://m.jb51.net/android/game/826.html"}})();
</script>
方法三:
<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://m.16css.com/";
}
}
}
catch(err){
}
</script>
方法四:
<script type="text/javascript">
// JavaScript Document
function urlredirect() {
var sUserAgent = navigator.userAgent.toLowerCase();
if ((sUserAgent.match(/(ipod|iphone os|midp|ucweb|android|windows ce|windows mobile)/i))) {
// PC跳转移动端
var thisUrl = window.location.href;
window.location.href = thisUrl.substr(0,thisUrl.lastIndexOf('/')+1)+'mobile/';
}
}
urlredirect();
</script>
方法五:
直接把以下代码另存一个shouji.js写到PC端网址模板首页
<script src="/js/shouji.js" type="text/javascript"></script>
//这样直接在手机上访问PC端网址,即可在手机上实现自动跳转对应的手机端网站
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "//hm.baidu.com/hm.js?";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
var mobileAgent = new Array("iphone", "ipod", "ipad", "android", "mobile", "blackberry", "webos", "incognito", "webmate", "bada", "nokia", "lg", "ucweb", "skyfire");
var browser = navigator.userAgent.toLowerCase();
var isMobile = false;
for (var i=0; i<mobileAgent.length; i++){
if (browser.indexOf(mobileAgent[i])!=-1){
isMobile = true;
location.href = 'http://m.nk91.com/';
break;
}
}