预览模式: 普通 | 列表

js判断是pc还是移动端

利用了正则表达式和三目运算符,含义就是如果是移动端打开的话那就跳转到 "https:www.baidu.com/" ,如果不是就跳转到"http://new.baidu.com/"
 
window.location.href = /Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent) ? "https://www.baidu.com/" :  "http://news.baidu.com/";
 
等同于
 
if(/Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)) {
    window.location.href = "https://www.baidu.com/";
} else {
    window.location.href = "http://news.baidu.com/";
}

Tags: javascript

分类:技术文章 | 固定链接 | 评论: 0 | 引用: 0 | 查看次数: 122
使用WinHttpRequest伪造HTTP头信息,伪造Referer等信息
由于微软封锁了XmlHttp对象,所以无法伪造部分HTTP头信息,但是WinHttp.WinHttpRequest.5.1对象,它居然用可以成功伪造所有http请求的header信息!
 
从msdn得知,WinHttp.WinHttpRequest.5.1是msxml4.0的底层对象,也就是说XMLHTTP/ServerXMLHTTP也是在它的基础上封装而来,WinHttpRequest的用法与XmlHttp大致相同。
 
WaitForResponse在使用异步方式发送请求时,可以用这个方法来控制请求的进程,指定的等待时间,以秒为一个异步传送方法来完成的值,SetTimeouts。
 
在服务端脚本中,不可以像客户端那样直接使用回调函数来控制异步请求,也没有相应的函数来使用程序休眠一定的时间,因此,为了等待请求返回,我们可以使用这个方法来等待一定时间。
 
代码如下:
<% 
Dim WinHttp 
Set WinHttp = Server.CreateObject("WinHttp.WinHttpRequest.5.1") 
'设置参数 
WinHttp.SetTimeouts 60000, 60000, 60000, 3000 '设置操作超时时间 
'WinHttp.SetTimeouts resolveTimeout, connectTimeout, sendTimeout, receiveTimeout 
'resolveTimeout = 10000 '解析 DNS 名字的超时时间,10000 毫秒。 
'connectTimeout = 10000 '建立 Winsock 连接的超时时间,10000 毫秒。 
'sendTimeout = 120000 '发送数据的超时时间,120000 毫秒。 
'receiveTimeout = 60000 '接收 response 的超时时间,60000 毫秒。 
WinHttp.Option(4) = 13056 '忽略错误标志 
WinHttp.Option(6) = False '为 True 时,当请求页面重定向跳转时自动跳转,False 不自动跳转,截取服务端返回的302状态。 
WinHttp.Open "GET", "http://www.baidu.com/", False 'GET 或 POST, Url, False 同步方式;True 异步方式 
'组成 HTTP 头信息 
WinHttp.SetRequestHeader "Accept", "*/*" '接受数据类型 
WinHttp.SetRequestHeader "Accept-Language", "zh-cn,zh" '用户系统语言 
WinHttp.SetRequestHeader "User-Agent", "Mozilla/6.0" '用户浏览器信息 
WinHttp.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded" '编码方式 
WinHttp.SetRequestHeader "Referer", "http://www.baidu.com/" '来路 
WinHttp.SetRequestHeader "Connection", "Close" 'Close = 不保持连接,Keep-Alive = 保持连接(持久连接) 
'WinHttp.SetRequestHeader "Accept-Encoding", "gzip, deflate" '如果发送,会返回 gzip, deflate 压缩过的编码 
'WinHttp.SetRequestHeader "Content-Length", Len(Str) '内容长度,Post 方式用的。 
WinHttp.SetRequestHeader "Cookie", "test cookie!" '设置 Cookie 
'发送数据 
WinHttp.Send 'Post 方式:WinHttp.Send (参数) 
WinHttp.WaitForResponse '等待返回请求,XMLHTTP中也可以使用 
'输出结果 
Response.Write WinHttp.Status '当前 HTTP 状态 
'Response.Write WinHttp.ResponseText '文本数据 
Response.BinaryWrite WinHttp.ResponseBody '二进制数据流数据 
%>
 
Option()相关: 
 
WinHttpRequestOption_UserAgentString = 0; 
WinHttpRequestOption_URL = 1; 
WinHttpRequestOption_URLCodePage = 2; 
WinHttpRequestOption_EscapePercentInURL = 3; 
WinHttpRequestOption_SslErrorIgnoreFlags = 4; 
WinHttpRequestOption_SelectCertificate = 5; '13056 = 忽略错误标志 
WinHttpRequestOption_EnableRedirects = 6; '为True时,当请求的页面中有跳转时,抓取跳转页面信息.False相反不抓取 
WinHttpRequestOption_UrlEscapeDisable = 7; 
WinHttpRequestOption_UrlEscapeDisableQuery = 8; 
WinHttpRequestOption_SecureProtocols = 9; 
WinHttpRequestOption_EnableTracing = 10; 
WinHttpRequestOption_RevertImpersonationOverSsl = 11; 
WinHttpRequestOption_EnableHttpsToHttpRedirects = 12; 
WinHttpRequestOption_EnablePassportAuthentication = 13; 
WinHttpRequestOption_MaxAutomaticRedirects = 14; 
WinHttpRequestOption_MaxResponseHeaderSize = 15; 
WinHttpRequestOption_MaxResponseDrainSize = 16; 
WinHttpRequestOption_EnableHttp1_1 = 17; 
 
WinHttpRequestOption_EnableCertificateRevocationCheck = 18; 
 
方法 Description 说明 
 
Abort 中止一个WinHTTP的 发送方法。 
GetAllResponseHeaders 检索所有的HTTP响应头。 
GetResponseHeader 检索HTTP响应头。 
Open 打开一个HTTP连接到HTTP资源。 
Send 发送一个HTTP请求到HTTP服务器。 
SetAutoLogonPolicy 设置当前自动登录策略。 
SetClientCertificate 选择一个客户端证书发送到一个安全的超文本传输协议(HTTPS)服务器。 
SetCredentials 设置要使用的凭据与HTTP服务器,要么是原籍国或代理服务器。 
SetProxy 设置代理服务器信息。 
SetRequestHeader 添加,更改或删除一个HTTP请求标头。 
SetTimeouts 指定以毫秒为单位,个人的时间超过了一个组件发送/接收操作。 
WaitForResponse 指定的等待时间,以秒为一个异步传送方法来完成的值,SetTimeouts。 
 
该 WinHttpRequest 对象定义以下属性。 
属性 访问类型 说明 
 
Option 读/写 设置或检索一个WinHTTP的选项值。 
ResponseBody 只读 检索作为无符号字节数组的响应实体机构。 
ResponseStream 只读 检索机构作为响应实体的IStream。 
ResponseText 只读 作为文本检索响应实体机构。 
Status 只读 从上次检索响应的HTTP状态代码。 
StatusText 只读 获取HTTP状态的文本。 
 
Events 活动 
 
The WinHttpRequest object defines the following events. 
WinHttpRequest 对象定义的下列事件。 
 
Event 事件 Description说明 
 
OnError Occurs when there is a run-time error in the application. 
当发生一个应用程序运行时错误时发生。 
OnResponseDataAvailable Occurs when data is available from the response. 
当响应数据可用时发生。 
OnResponseFinished Occurs when the response data is complete. 
响应数据完成时发生。 
OnResponseStart Occurs when the response data starts to be received. 
开始收到响应数据时发生。 
 
Remarks 备注 
 
The WinHttpRequest object uses the IErrorInfo interface to provide error data. 
该 WinHttpRequest 对象使用 IErrorInfo 接口来提供错误数据。 
A description and numerical error value can be obtained with the Err object in Microsoft Visual Basic Scripting Edition (VBScript), 
and the Error object in Microsoft JScript. 
The lower 16 bits of an error number correspond to the values found in Error Messages. 
Note For Windows XP and Windows 2000, see Run-Time Requirements. 
注意:对于 Windows XP 和 Windows 2000,请参阅运行时间要求。 
 
Requirements 要求 
 
最低支持的客户端 Windows XP, Windows 2000 Professional with SP3 Windows XP 
最低支持的服务器 Windows Server 2003, Windows 2000 Server with SP3 
 
可再发行 WinHTTP 5.0 and Internet Explorer 5.01 or later on Windows XP and Windows 2000. 
WinHTTP的5.0和Internet Explorer 5.01或更高版本的Windows XP和Windows 2000。 
IDL HttpRequest.idl HttpRequest.idl 
Library Winhttp.lib Winhttp.lib 
DLL Winhttp.dll Winhttp.dll

Tags: winhttp

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

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 | 查看次数: 173

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 | 查看次数: 143
通过判断浏览器的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 | 查看次数: 150

 广告位

↑返回顶部↑