JavaScript 判断浏览器类型及版本
$(document).ready(function() {
var Sys = {};
var ua = navigator.userAgent.toLowerCase();
if (window.ActiveXObject)
Sys.ie = ua.match(/msie ([\d.]+)/)[1]
else if (document.getBoxObjectFor)
Sys.firefox = ua.match(/firefox\/([\d.]+)/)[1]
else if (window.MessageEvent && !document.getBoxObjectFor)
Sys.chrome = ua.match(/chrome\/([\d.]+)/)[1]
else if (window.opera)
Sys.opera = ua.match(/opera.([\d.]+)/)[1]
else if (window.openDatabase)
Sys.safari = ua.match(/version\/([\d.]+)/)[1];
//以下进行测试
if (Sys.ie) $("#llq").html("IE:" + Sys.ie);
if (Sys.firefox) $("#llq").html("Firefox: " + Sys.firefox);
if (Sys.chrome) $("#llq").html('Chrome: ' + Sys.chrome);
if (Sys.opera) $("#llq").html('Opera: ' + Sys.opera);
if (Sys.safari) $("#llq").html('Safari: ' + Sys.safari);
})
相关文档:
function BOX_show(e,obj)//显示
{
if(obj<24)
document.cookie = "tdid="+obj;
if(document.getElementById(e)==null)
{
return ;
}
&n ......
使用try{...}catch(){} 方式,例子如下:
function showAlarm(strObject){
try{
svgElement = document.getElementById(strObject);
svgElement.setAttribute("visibility","visible");
setTimeout("hideAlarm()",3000);//3秒后结束报警
}catch(ex){
alert("函数showAlarm()发生异常:"+ex.descrip ......
window
window对象是浏览器或者框架自身.top总是浏览器,parent是父框架,self表示自己.
window通常可以省略.
窗口操作: moveBy(dx, dy), moveTo(x, y),
resizeBy(dw, dh), resizeTo(w, h).
导航: window.open(url, frame
name, attribute). attribute可以是left, top, height, width, resizable,
scrollable, too ......
正则表达式
RegExp(regexp, option)类实现,可以简写成/regexp/option
option:
g: global, i: ignore case
方法:string.test(regexp),
string.exec(regexp)[返回所有匹配的地方], string.serch(regexp)[正则版的indexOf()],
string.replace(regexp, str|funtion), string.split(regexp)
简单模式
元字符:( [ {
......