function isWechat() {
var ua = navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == 'micromessenger') {
return true;
} else {
return false;
}
}
function isPC() {
var userAgentInfo = navigator.userAgent;
var Agents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPad', 'iPod'];
var flag = true;
for (var v = 0; v < Agents.length; v++) {
if (userAgentInfo.indexOf(Agents[v]) > 0) {
flag = false;
break;
}
}
return flag;
}
function getUrlParam(name, url) {
if (!url) url = location.href;
if (url.indexOf('?') == -1) return '';
try {
var re = new RegExp("" + name + "=([^&?]*)", "ig");
return ((url.match(re)) ? (decodeURIComponent(url.match(re)[0].substr(name.length + 1))) : '');
} catch (_e) {
return '';
}
}
function getCookie(name, defaultVal = null) {
var arr,
reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)');
if (arr = document.cookie.match(reg)) {
return unescape(arr[2]);
} else {
return defaultVal;
}
}
function setCookie(name, value, seconds) {
var expires = new Date();
expires.setTime(expires.getTime() + parseInt(seconds) * 1000);
var domain = document.domain;
var domainArr = domain.split('.');
if (domainArr.length >= 3) {
domainArr.shift();
domain = domainArr.join('.');
}
document.cookie = escape(name) + '=' + escape(value) + (seconds ? ('; expires=' + expires.toGMTString()) : "") + '; path=/; domain=.' + domain + ';';
}
// this指上面的方法
function delCookie(name) {
this.setCookie(name, '', -1);
}
function toDesktop(sUrl,sName){
try {
var WshShell = new ActiveXObject("WScript.Shell");
var oUrlLink = WshShell.CreateShortcut(WshShell.SpecialFolders("Desktop")+ "\\" + sName + ".url");
oUrlLink.TargetPath = sUrl;
oUrlLink.Save();
}catch(e){
alert("当前IE安全级别不允许操作!");
}
}
function AddFavorite(title, url){
try {
window.external.addFavorite(url, title);
}catch (e) {
try {
window.sidebar.addPanel(title, url, "");
}catch (e) {
alert("抱歉,您所使用的浏览器无法完成此操作。\n\n加入收藏失败,请使用Ctrl+D进行添加");
}
}
}
function isEmpty(val){
if(typeof val == "undefined" || val == null || val == ""){
return true;
} else {
return false;
}
}
function inArray(search, array) {
for (var i in array) {
if (array[i] == search) {
return true;
}
}
return false;
}
function arrayUnique(arr) {
return [...new Set(arr)];
}
function setLocalstorage(key, value) {
if(!window.Storage) {
console.error("该浏览器不支持Localstorage属性!!");
return false;
} else {
localStorage.setItem(key, value);
}
}
function getLocalstorage(key) {
var value = localStorage.getItem(key);
if (value) {
try {
var value_json = JSON.parse(value);
if (typeof value_json === 'object') {
return value_json;
} else if (typeof value_json === 'number') {
return value_json;
}
} catch(e) {
return value;
}
} else {
return false;
}
}
function removeLocalstorage(key) {
localStorage.removeItem(key);
}
function clearLocalstorage() {
localStorage.clear();
}