封装的head
//获取浏览器和版本号
var userAgent=window.navigator.userAgent,
rMsie=/(msie\s|trident.*rv:)([\w.]+)/,
rFirefox=/(firefox)\/([\w.]+)/,
rOpera=/(opera).+version\/([\w.]+)/,
rChrome=/(chrome)\/([\w.]+)/,
rSafari=/version\/([\w.]+).*(safari)/;
function uaMatch(ua)
{
var match=rMsie.exec(ua);
if(match != null)
{
return {browser:"IE",version:match[2] || "0"};
}
var match=rFirefox.exec(ua);
if(match != null)
{
return {browser:match[1] || "",version:match[2] || "0"};
}
var match=rOpera.exec(ua);
if(match != null)
{
return {browser:match[1] || "",version:match[2] || "0"};
}
var match=rChrome.exec(ua);
if(match != null)
{
return {browser:match[1] || "",version:match[2] || "0"};
}
var match=rSafari.exec(ua);
if(match != null)
{
return {browser:match[2] || "",version:match[1] || "0"};
}
if(match != null)
{
return {browser:"",version:"0"};
}
}
var browser="";
var version="";
var browserMatch=uaMatch(userAgent.toLowerCase());
if(browserMatch.browser)
{
browser=browserMatch.browser;
version=browserMatch.version;
}
/*console.log(browser);//浏览器
console.log(version);//版本号*/
var str=browser;
var str2="";
function demo(str){
for(var i=0;i<str.length;i++){
str2+=str.charAt(str.length-i-1);
}
console.log(str+"<br />"+str2)
}
demo(str);
var str3=version;
var str4="";
function demoe(str3){
for(var i=0;i<str3.length;i++){
str4+=str3.charAt(str3.length-i-1);
}
console.log(str3+"<br />"+str4)
}
demoe(str3)
//封装请求头
var head={
'machine-code': str,
'network-code':str3,
'current-time':getNowFormatDate(),
'token':str2+str4+getNowFormatDate(),
}
//console.log(head);打印出来的head