惯用JS功能

常用JS功能判断是否是IE var isIE!!window.ActiveXObject var isIE6isIE&&!window.XMLHttpRequest var

常用JS功能

判断是否是IE

var isIE=!!window.ActiveXObject; var isIE6=isIE&&!window.XMLHttpRequest; var isIE8=isIE&&!!document.documentMode; var isIE7=isIE&&!isIE6&&!isIE8;
?

判断是否为Firefox

if(navigator.userAgent.indexOf("Firefox")!=-1){ }
?

退出系统

function close(evt){ //author: sunlei      var isIE=document.all?true:false;      evt = evt ? evt :(window.event ? window.event : null);      if(isIE){//IE浏览器          var n = evt.screenX - window.screenLeft;          var b = n > document.documentElement.scrollWidth-20;          if(b && evt.clientY<0 || evt.altKey){          }          else{                  window.location.href="${pageContext.request.contextPath}/exit.jsp";          }      }      else{//火狐浏览器          if(document.documentElement.scrollWidth!=0)              window.location.href="${pageContext.request.contextPath}/exit.jsp";      }  }
?

加入收藏夹

if(!window.ActiveXObject){alert('非IE浏览器版本不支持该功能!');return false;};window.external.addFavorite('<%=basePath%>','XXX管理系统');
?

页面上显示一个时钟

function thistime(){      var webjx = document.getElementById("webjx");   var today = new Date();   var month = today.getMonth()+1;   var timestr=today.getFullYear() +'-'+ month +'-'+ today.getDate() +" "+ today.getHours() +":"+ today.getMinutes() +":"+ today.getSeconds();   webjx.innerHTML= timestr +' 星期'+'日一二三四五六'.charAt(new Date().getDay());  }  setInterval(thistime,1000);
?

创建桌面快捷方式

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();  alert("恭喜您,添加成功!");  }catch(e){       alert("当前IE安全级别不允许操作!");    }}
?

js跳转到相关页面

location.href = "${pageContext.request.contextPath}/deptr/basic/main.do";
?

强制当前页面在最顶部的frame打开,常用于系统用户没有登陆,强制用户登陆页面在最顶部的frame中打开,防制在内嵌的Frame中打开。

if(self.location != top.location)   top.location = self.location;

?

获取工程目录

function getRootPath() { var strFullPath = window.document.location.href; var strPath = window.document.location.pathname; var pos = strFullPath.indexOf(strPath); var prePath = strFullPath.substring(0, pos); var postPath = strPath.substring(0, strPath.substr(1).indexOf("/") + 1); return postPath;}

?

网页中定位常用的一部属性

function test(obj)   {    alert("鼠标事件的X坐标:"+event.clientX);    alert("鼠标事件的Y坐标:"+event.clientY);    alert("body即可视区的宽度:"+document.body.clientWidth);    alert("body即可视区的高度:"+document.body.clientHeight);    alert("某对象的宽度:"+obj.offsetWidth);    alert("某对象的高度:"+obj.offsetHeight);    alert("某对象与它的父元素的左边的距离:"+obj.offsetLeft);    alert("某对象与它的父元素的上边的距离:"+obj.offsetTop);       }
?