第54章
作者:佚名    更新:2021-12-03 10:35
  131,Q:用 Javascript 存取剪贴板:
  A:
  132,Q:网页中判断 IE 客户端是否装有 office
  A:
  function CheckExcel()
  {
  try
  {new ActiveXObject("WScript.Shell");}
  catch(x) {return false;}
  try
  {new ActiveXObject("Excel.Application");}
  catch(x){return null;}
  return true;
  }
  res=CheckExcel();
  switch(res)
  {
  case true:
  alert("安装有 EXCEL"); break;
  case null:
  alert("没有安装"); break;
  case false:
  alert("ActiveX 被禁用");
  }
  133,Q:Javascript 命令参数 external 的几个用法:
  A: Window.external 就如同 print 参数一样,是 IE 默认的一个命令参数,我们最常用的用法是:
  (1)、external.AddDesktopComponent:把某一个网页变成用户的桌面。如果你知道有壁纸网站的话,不访用这个功能,直接就能让浏览者把喜欢的图片、页面变成自己的桌面。如果页面里有 Flash 动画那就更酷了。
  function wallpaper()
  {window.external.AddDesktopComponent("url","title",0,0,1024,768);}
  (2)、external.AddFavorite:把网站加入到用户的收藏夹。在页面上添加一个按钮,让浏览者可以方便地把页面地址保存在 IE 收藏夹里。
  function add()
  {window.external.AddFavorite("url","title");}
  如果把 url 和 title 替换成 this.location.href, this.document.title 则自动把当前页面地址及其标题添加到浏览器收藏夹。
  (3)、window.external.ShowBrowserUI:启动 IE 的“语言设置”和“整理收藏夹”功能。
  134,Q:干掉免费个人主页上强加的广告窗口、广告条
  A:一些免费主页经常在你的主页上强加各种类型的广告,很是烦人。但如果注意到它们都是以明文文本代码的形式加在网页中的某个固定的地方,则要干掉它们就不是很困难了。站长收集了一些技巧贴出来供大家参考:
  1)、利用  注解标志来欺骗。
  例如
  处插进去的
  // 这才是真的 body!
  2)用<META 这个标志来欺骗。
  例如:
  前面,插在这,等于没插
  3)直接利用下面的代码屏蔽掉广告代码中弹出窗口用的函数 open()
  <!--
  function open() {return true;} // OK,这就是我们要的
  //-->
  4)有的时候广告代码前会放 就搞定了。
  // 下面是广告插入的代码。
  ......
  5)屏蔽掉广告打开的指定页面。
  <!--
  function ScreenIt(url,name,parm)
  {
  if(url.indexOf("popup.html")!=-1) return false; // popup.html 是广告页面。
  return window.Xopen(url,name,parm);
  }
  window.Xopen=window.open;
  window.open=ScreenIt;
  //-->
  6)干掉包含指定名字的弹出窗口
  <!--
  function ScreenIt(url,name,parm)
  {
  if(name.indexOf("opup")!=-1) return false; //广告窗口名字包含“opup”
  return window.Xopen(url,name,'toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1');
  }
  window.Xopen=window.open;
  window.open=ScreenIt;
  //-->
  135,Q:屏蔽 IE 的右键菜单,并定制自己的右键菜单
  A:
  #ie5menu
  {
  position:absolute;
  width:150px;
  border:1px solid green;
  background-color:menu;
  font-family:Verdana;
  font-size:9pt;
  line-height:20px;
  cursor:hand;
  visibility:hidden;
  }
  .menuitems
  {
  padding-left:15px;
  padding-right:15px;
  }
  -->
  //set this variable to 1 if you wish the URLs of
  //the highlighted menu to be displayed in the status bar
  var display_url=0
  function showmenuie5()
  {
  var rightedge=document.body.clientWidth-event.clientX
  var bottomedge=document.body.clientHeight-event.clientY
  if (rightedge<ie5menu.offsetWidth)
  ie5menu.style.left=document.body.scrollLeft+event.clientX-ie5menu.offsetWidth
  else
  ie5menu.style.left=document.body.scrollLeft+event.clientX
  if (bottomedge<ie5menu.offsetHeight)
  ie5menu.style.top=document.body.scrollTop+event.clientY-ie5menu.offsetHeight
  else
  ie5menu.style.top=document.body.scrollTop+event.clientY
  ie5menu.style.visibility="visible"
  return false
  }
  function hidemenuie5()
  {
  ie5menu.style.visibility="hidden"
  }
  function highlightie5()
  {
  if(event.srcElement.className=="menuitems")
  {
  event.srcElement.style.cursor="hand"
  event.srcElement.style.backgroundColor="highlight"
  event.srcElement.style.color="white"
  if(display_url==1) window.status=event.srcElement.url
  }
  else
  event.srcElement.style.cursor="default"
  }
  function lowlightie5()
  {
  if (event.srcElement.className=="menuitems")
  {
  event.srcElement.style.backgroundColor=""
  event.srcElement.style.color="black"
  window.status=''
  }
  }
  function jumptoie5()
  {
  if(event.srcElement.className=="menuitems") window.location=event.srcElement.url
  }
  document.oncontextmenu=showmenuie5
  if (document.all && window.print) document.body.onclick=hidemenuie5;
  点击右键打开菜单
  136,Q:如何用 javascript 判断输入的日期是否有效
  A:主要原理是把得到的年月日拼成字符串与客户端输入的做比较,如相等则对,否则错。