预览模式: 普通 | 列表

jQuery跳转到另一个页面

1.我们可以利用http的重定向来跳转

 
window.location.replace("http://www.baidu.com");
 
2.使用href来跳转
 
window.location.href = "http://www.baidu.com";
 
3.使用jQuery的属性替换方法
 
$(location).attr('href', 'http://www.baidu.com');
 
$(window).attr('location','http://www.baidu.com');
 
$(location).prop('href', 'http://www.baidu.com');

Tags: javascript jquery

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 177

js区分苹果手机,安卓手机和windows手机

 区分苹果手机,安卓手机和其他

 
var u = navigator.userAgent;
if (u.indexOf('Android') > -1 || u.indexOf('Linux') > -1) {//安卓手机
WebViewJavascriptBridge.callHandler(
'jsCallAndroid', index,
function(responseData) {
// document.getElementById("show").innerHTML = "send get responseData from java, data = " + responseData
}
);
} else if (u.indexOf('iPhone') > -1) {//苹果手机
jsCallOC('IntValue',index);
} else {//winphone手机
alert("winphone手机");
}

Tags: javascript

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 146
通过判断浏览器的userAgent,用正则来判断手机是否是ios和Android客户端。网上搜索来的,比较简单:
var u = navigator.userAgent;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //android终端
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
下面一个比较全面的浏览器检查函数,提供更多的检查内容,你可以检查是否是移动端Mobile、ipad、iphone、微信、QQ等。
 
//判断访问终端
var browser={
    versions:function(){
        var u = navigator.userAgent, app = navigator.appVersion;
        return {
            trident: u.indexOf('Trident') > -1, //IE内核
            presto: u.indexOf('Presto') > -1, //opera内核
            webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
            gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1,//火狐内核
            mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
            ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
            android: u.indexOf('Android') > -1 || u.indexOf('Adr') > -1, //android终端
            iPhone: u.indexOf('iPhone') > -1 , //是否为iPhone或者QQHD浏览器
            iPad: u.indexOf('iPad') > -1, //是否iPad
            webApp: u.indexOf('Safari') == -1, //是否web应该程序,没有头部与底部
            weixin: u.indexOf('MicroMessenger') > -1, //是否微信 (2015-01-22新增)
            qq: u.match(/\sQQ/i) == " qq" //是否QQ
        };
    }(),
    language:(navigator.browserLanguage || navigator.language).toLowerCase()
}
使用也很简单:
 
//判断是否IE内核
if(browser.versions.trident){ alert("is IE"); }
//判断是否webKit内核
if(browser.versions.webKit){ alert("is webKit"); }
//判断是否移动端
if(browser.versions.mobile||browser.versions.android||browser.versions.ios){ alert("移动端"); }
 
检测浏览器语言
 
//code from http://caibaojian.com/browser-ios-or-android.html
currentLang = navigator.language;   //判断除IE外其他浏览器使用语言
if(!currentLang){//判断IE浏览器使用语言
    currentLang = navigator.browserLanguage;
}
alert(currentLang);

Tags: javascript

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 152

 广告位

↑返回顶部↑