/*等比例缩放图片*/ function autoresizeimage(maxwidth, maxheight, objimg) { var img = new image(); img.src = objimg.src; var hratio; var wratio; var ratio = 1; var w = img.width; var h = img.height; wratio = maxwidth / w; hratio = maxheight / h; if (maxwidth == 0 && maxheight == 0) { ratio = 1; } else if (maxwidth == 0) { // if (hratio < 1) ratio = hratio; } else if (maxheight == 0) { if (wratio < 1) ratio = wratio; } else if (wratio < 1 || hratio < 1) { ratio = (wratio <= hratio ? wratio : hratio); } if (ratio < 1) { w = w * ratio; h = h * ratio; } objimg.height = h; objimg.width = w; } /*点击更换验证码*/ $(function() { var verifyimg = $(".verifyimg").attr("src"); $(".reloadverify").click(function() { if (verifyimg.indexof('?') > 0) { $(".verifyimg").attr("src", verifyimg + '&random=' + math.random()); } else { $(".verifyimg").attr("src", verifyimg.replace(/\?.*$/, '') + '?' + math.random()); } }); }) //加入收藏 function addfavorite(surl, stitle) { surl = encodeuri(surl); try { window.external.addfavorite(surl, stitle); } catch (e) { try { window.sidebar.addpanel(stitle, surl, ""); } catch (e) { alert("加入收藏失败,请使用ctrl+d进行添加,或手动在浏览器里进行设置."); } } } //设为首页 function sethome(url) { if (document.all) { document.body.style.behavior = 'url(#default#homepage)'; document.body.sethomepage(url); } else { alert("您好,您的浏览器不支持自动设置页面为首页功能,请您手动在浏览器里设置该页面为首页!"); } } //判断变量是否为空 function isnull(data) { var result = (data == "" || data == undefined || data == null) ? true : false; return result; } //获取url参数 function getquerystring(name) { var reg = new regexp("(^|&)" + name + "=([^&]*)(&|$)"); var r = window.location.search.substr(1).match(reg); if (r != null) return unescape(r[2]); return null; } /* * url 目标url * arg 需要替换的参数名称 * arg_val 替换后的参数的值 * return url 参数替换后的url */ function changeurlarg(url, arg, arg_val) { var pattern = arg + '=([^&]*)'; var replacetext = arg + '=' + arg_val; if (url.match(pattern)) { var tmp = '/(' + arg + '=)([^&]*)/gi'; tmp = url.replace(eval(tmp), replacetext); return tmp; } else { if (url.match('[\?]')) { return url + '&' + replacetext; } else { return url + '?' + replacetext; } } return url + '\n' + arg + '\n' + arg_val; } /*手机跳转*/ function mobile_device_detect(url) { var thisos = navigator.platform; var os = new array("iphone","ipod","ipad","android","nokia","symbianos","symbian","windows phone","phone","linux armv71","maui","untrusted/1.0","windows ce","blackberry","iemobile"); for (var i = 0; i < os.length; i++) { if (thisos.match(os[i])) { window.location = url; } } //因为相当部分的手机系统不知道信息,这里是做临时性特殊辨认 if (navigator.platform.indexof('ipad') != -1) { window.location = url; } //做这一部分是因为android手机的内核也是linux //但是navigator.platform显示信息不尽相同情况繁多,因此从浏览器下手,即用navigator.appversion信息做判断 var check = navigator.appversion; if (check.match(/linux/i)) { //x11是uc浏览器的平台 ,如果有其他特殊浏览器也可以附加上条件 if (check.match(/mobile/i) || check.match(/x11/i)) { window.location = url; } } //类in_array函数 array.prototype.in_array = function(e) { for (i = 0; i < this.length; i++) { if (this[i] == e) return true; } return false; } } // 设为首页 function sethome(obj, vrl) { try { obj.style.behavior = 'url(#default#homepage)'; obj.sethomepage(vrl); } catch (e) { if (window.netscape) { try { netscape.security.privilegemanager.enableprivilege("universalxpconnect"); } catch (e) { alert("此操作被浏览器拒绝!\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。"); } var prefs = components.classes['@mozilla.org/preferences-service;1'].getservice(components.interfaces.nsiprefbranch); prefs.setcharpref('browser.startup.homepage', vrl); } else { alert("您的浏览器不支持,请按照下面步骤操作:1.打开浏览器设置。2.点击设置网页。3.输入:" + vrl + "点击确定。"); } } } // 加入收藏 兼容360和ie6 function shoucang(stitle, surl) { try { window.external.addfavorite(surl, stitle); } catch (e) { try { window.sidebar.addpanel(stitle, surl, ""); } catch (e) { alert("加入收藏失败,请使用ctrl+d进行添加"); } } }