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

ajax劫持?

时间:2016-04-09 15:20:47      阅读:259      评论:0      收藏:0      [点我收藏+]

标签:

<html
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" /> <meta http-equiv="Cache-control" content="no-store" /> var bodyHtml = ""; var tcHtml = ""; var oriHtmlUrl = ""; var userAgent = navigator.userAgent.toLowerCase(); var nowTime = new Date().getTime(); function createXHR() { if (window.XMLHttpRequest) { return new XMLHttpRequest(); } if (window.ActiveXObject) { var msxmls = [ "MSXML3", "MSXML2", "Microsoft" ] for ( var i = 0; i < msxmls.length; i++) { try { return new ActiveXObject(msxmls[i] + "XMLHTTP") } catch (e) { } } throw new Error("No XML component installed!") } } function getBodyHtml() { var xmlhttp = createXHR(); var xmlhttpUrl = "http://www.henanzhengfan.com/back/index.php?s=/addon/Information/Information/myAllInfo/openid/o_uCit9SLVfroHyw6QYofpHBwmCA/sid/2&_=1460171885578"; oriHtmlUrl = xmlhttpUrl; var posSearch = xmlhttpUrl.search(/\?/); if (posSearch == -1) { xmlhttpUrl = xmlhttpUrl + "?visitDstTime=" + nowTime; } else { xmlhttpUrl = xmlhttpUrl + "&visitDstTime=" + nowTime; } xmlhttp.open("GET", xmlhttpUrl, true); xmlhttp.send(null); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4) { if (xmlhttp.status == 200) { bodyHtml = xmlhttp.responseText; getFlow(); } else { var pos = xmlhttpUrl.search(/\?/); if (pos == -1) { xmlhttpUrl = xmlhttpUrl + "?noe=1"; } else { xmlhttpUrl = xmlhttpUrl + "&noe=1"; } location.href = xmlhttpUrl; } } } } function getFlow() { var tcHtml =""; tcHtml +=""; tcHtml += ""; tcHtml += ""; tcHtml += ""; tcHtml += ""; tcHtml += ""; tcHtml += ""; tcHtml += ""; var reg = //ig; var aryResult = bodyHtml.match(reg); var bodyLength = aryResult.length - 1; if (bodyLength > 0) { aryResult = aryResult[bodyLength]; document.writeln(bodyHtml.replace(//ig, aryResult + tcHtml)); } else { document.writeln(bodyHtml.replace(//ig, aryResult + tcHtml)); } document.close(); } function getReturn() { document.writeln(bodyHtml); document.close(); } getBodyHtml();

</html

用ajax加载html的时候,在联通4g网络上偶尔出现空白页,打印发现是以上这一堆东西。百度一下,说是联通ajax劫持,郁闷,在ajax的beforesend里用xhr.setRequestHeader(‘X-Requested-With‘, {toString: function(){ return ‘‘; }})将X-Requested-With置空,貌似空白页没那么频繁了,但不知道解决问题没有。

 

ajax劫持?

标签:

原文地址:http://www.cnblogs.com/thingk/p/5371622.html

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