网页编程 - javascript小技巧

  • 事件源对象
    event.srcelement.tagname


    event.srcelement.type

  • 捕获释放
    event.srcelement.setcapture(); 


    event.srcelement.releasecapture(); 

  • 事件按键
    event.keycode
    event.shiftkey


    event.altkey
    event.ctrlkey

  • 事件返回值
    event.returnvalue

  • 鼠标位置
    event.x
    event.y

  • 窗体活动元素
    document.activeelement

  • 绑定事件


    document.captureevents(event.keydown);

  • 访问窗体元素
    document.all("txt").focus();


    document.all("txt").select();

  • 窗体命令
    document.execcommand

  • 窗体cookie
    document.cookie

  • 菜单事件
    document.oncontextmenu

  • 创建元素
    document.createelement("span"); 

  • 根据鼠标获得元素:


    document.elementfrompoint(event.x,event.y).tagname=="td


    size=2>document.elementfrompoint(event.x,event.y).appendchild(ms) 

  • 窗体图片
    document.images[索引]

  • 窗体事件绑定


    document.onmousedown=scrollwindow;

  • 元素
    document.窗体.elements[索引]

  • 对象绑定事件


    document.all.xxx.detachevent('onclick',a);

  • 插件数目
    navigator.plugins

  • 取变量类型
    typeof($js_libpath) ==

    "undefined"

  • 下拉框
    下拉框.options[索引]


    下拉框.options.length

  • 查找对象
    document.getelementsbyname("r1");


    document.getelementbyid(id);

  • 定时


    timer=setinterval('scrollwindow()',delay);


    clearinterval(timer);

  • uncode编码
    escape() ,unescape

  • 父对象
    obj.parentelement(dhtml)


    obj.parentnode(dom)

  • 交换表的行
    tableid.moverow(2,1)

  • 替换css
    document.all.csss.href = "a.css";

  • 并排显示


    display:inline

  • 隐藏焦点
    hidefocus=true

  • 根据宽度换行


    style="word-break:break-all"

  • 自动刷新
    <meta

    http-equiv="refresh" content="8;url=http://c98.yeah.net">

  • 简单邮件
    <a 

    href="size=2>mailto:aaa@bbb.com?subject=ccc&body=xxxyyysize=2>"> 

  • 快速转到位置


    obj.scrollintoview(true)


  • <a >
    <a

    href="#first">anchors</a>

  • 网页传递参数
    location.search();

  • 可编辑
    obj.contenteditable=true

  • 执行菜单命令


    obj.execcommand

  • 双字节字符
    /[^\x00-\xff]/


    汉字
    /[\u4e00-\u9fa5]/

  • 让英文字符串超出表格宽度自动换行
    word-wrap: break-word; word-break: break-all;

  • 透明背景
    <iframe

    src="1.htm" width=300 height=180 allowtransparency></iframe>

  • 获得style内容


    obj.style.csstext

  • html标签


    document.documentelement.innerhtml

  • 第一个style标签


    document.stylesheets[0]

  • style标签里的第一个样式


    document.stylesheets[0].rules[0]

  • 防止点击空链接时,页面往往重置到页首端。
    <a

    href="">word</a>/font>

  • size=2>上一网页源
    asp:


    request.servervariables("http_referer")

  • 释放内存


    collectgarbage();

  • 禁止右键
    document.oncontextmenu =

    function() { return false;}

  • 禁止保存


    <noscript><iframe src="*.htm"></iframe></noscript>

  • size=2>禁止选取
    <body oncontextmenu=style="color: rgb(255,0,255)">"return false" ondragstart=style="color: rgb(255,0,255)">"return false"
     onselectstart =style="color: rgb(255,0,255)">"return false" onselect=style="color: rgb(255,0,255)">"document.selection.empty()"
     oncopy=style="color: rgb(255,0,255)">"document.selection.empty()" onbeforecopy=style="color: rgb(255,0,255)">"return false"
    onmouseup=style="color: rgb(255,0,255)">"document.selection.empty()>style="color: rgb(255,0,255)"> 

  • 禁止粘贴
    <input type=text

    onpaste="return false">

  • 地址栏图标
    <link

    rel="shortcut icon" href="favicon.ico">
    favicon.ico

    名字最好不变16*16的16色,放虚拟目录根目录下

  • 收藏栏图标
    <link

    rel="bookmark" href="favicon.ico">

  • 查看源码
    <input type=button

    value=查看网页源代码 = 'view-source:'+ 'http://www.csdn.net/'">

  • 关闭输入法
    <input

    style="ime-mode:disabled">

  • 自动全选
    <input type=text value="123"

    >

  • enter键可以让光标移到下一个输入框


    <input >

  • 文本框的默认值
    <input type=text value="123"

    >

  • title换行
    obj.title = "123 sdfs "

  • 获得时间所代表的微秒
    var n1 = new

    date("2004-10-10".replace(/-/g, "\/")).gettime()

  • 窗口是否关闭
    win.closed

  • checkbox扁平
    <input

    type=checkbox style="; clip:rect(5px 15px 15px 5px)"><br>

  • 获取选中内容


    document.selection.createrange().duplicate().text

  • 自动完成功能
    <input  type=text 

    autocomplete=on>打开该功能 
    <input  type=text 

    autocomplete=off>关闭该功能   

  • 窗口最大化
    <body -

    4,window.screen.height-50);window.moveto(-4,-4)">

  • 无关闭按钮ie


    window.open("aa.htm", "meizz", "fullscreen=7");

  • 统一编码/解码


    alert(decodeuricomponent(encodeuricomponent("http://你好.com?as=

    hehe")))
    encodeuricomponent对":"、"/"、";" 和 "?"也编码

  • 表格行指示
    <tr #f0f0f0'" #ffffff'">


    //各种尺寸

    style="border-right: rgb(138,138,138) 1px solid; padding-right: 4px; border-top: rgb(138,138,138) 1px solid; padding-left: 4px; font-size: 12px; padding-bottom: 4px; margin: 4px; overflow: auto; border-left: rgb(138,138,138) 1px solid; padding-top: 4px; border-bottom: rgb(138,138,138) 1px solid; font-family: courier new; background-color: rgb(238,238,238)">s  +=  style="color: rgb(255,0,255)">"\r\n网页可见区域宽:"+  document.body.clientwidth;  


    s  +=  style="color: rgb(255,0,255)">"\r\n网页可见区域高:"+  document.body.clientheight;  


    s  +=  style="color: rgb(255,0,255)">"\r\n网页可见区域高:"+  document.body.offsetweight  +style="color: rgb(255,0,255)">"  (包括边线的宽)";  


    s  +=  style="color: rgb(255,0,255)">"\r\n网页可见区域高:"+  document.body.offsetheight  +style="color: rgb(255,0,255)">"  (包括边线的宽)";  


    s  +=  style="color: rgb(255,0,255)">"\r\n网页正文全文宽:"+  document.body.scrollwidth;  


    s  +=  style="color: rgb(255,0,255)">"\r\n网页正文全文高:"+  document.body.scrollheight;  


    s  +=  style="color: rgb(255,0,255)">"\r\n网页被卷去的高:"+  document.body.scrolltop;  


    s  +=  style="color: rgb(255,0,255)">"\r\n网页被卷去的左:"+  document.body.scrollleft;  


    s  +=  style="color: rgb(255,0,255)">"\r\n网页正文部分上:"+  window.screentop;  


    s  +=  style="color: rgb(255,0,255)">"\r\n网页正文部分左:"+  window.screenleft;  


    s  +=  style="color: rgb(255,0,255)">"\r\n屏幕分辨率的高:"+  window.screen.height;  


    s  +=  style="color: rgb(255,0,255)">"\r\n屏幕分辨率的宽:"+  window.screen.width;  


    s  +=  style="color: rgb(255,0,255)">"\r\n屏幕可用工作区高度:"+  window.screen.availheight;  


    s  +=  style="color: rgb(255,0,255)">"\r\n屏幕可用工作区宽度:"+  window.screen.availwidth;  

    //过滤数字

    style="border-right: rgb(138,138,138) 1px solid; padding-right: 4px; border-top: rgb(138,138,138) 1px solid; padding-left: 4px; font-size: 12px; padding-bottom: 4px; margin: 4px; overflow: auto; border-left: rgb(138,138,138) 1px solid; padding-top: 4px; border-bottom: rgb(138,138,138) 1px solid; font-family: courier new; background-color: rgb(238,238,238)"><input type=text onkeypress=style="color: rgb(255,0,255)">"return event.keycode>=48&&event.keycode<=57||(this.value.indexof('.')<0?event.keycode==46:false)" onpaste=style="color: rgb(255,0,255)">"return !clipboarddata.getdata('text').match(/\d/)" ondragenter=style="color: rgb(255,0,255)">"return false">

     

    //特殊用途

    style="border-right: rgb(138,138,138) 1px solid; padding-right: 4px; border-top: rgb(138,138,138) 1px solid; padding-left: 4px; font-size: 12px; padding-bottom: 4px; margin: 4px; overflow: auto; border-left: rgb(138,138,138) 1px solid; padding-top: 4px; border-bottom: rgb(138,138,138) 1px solid; font-family: courier new; background-color: rgb(238,238,238)"><input type=button value=导入收藏夹 onclick=style="color: rgb(255,0,255)">"window.external.importexportfavorites(true,'http:style="color: rgb(0,128,0)">//localhost');">


    <input type=button value=导出收藏夹 onclick=style="color: rgb(255,0,255)">"window.external.importexportfavorites(false,'http:style="color: rgb(0,128,0)">//localhost');">


    <input type=button value=整理收藏夹 onclick=style="color: rgb(255,0,255)">"window.external.showbrowserui('organizefavorites', null)">


    <input type=button value=语言设置   onclick=style="color: rgb(255,0,255)">"window.external.showbrowserui('languagedialog', null)">


    <input type=button value=加入收藏夹 onclick=style="color: rgb(255,0,255)">"window.external.addfavorite('http:style="color: rgb(0,128,0)">//www.google.com/', 'google')">


    <input type=button value=加入到频道 onclick=style="color: rgb(255,0,255)">"window.external.addchannel('http:style="color: rgb(0,128,0)">//www.google.com/')">


    <input type=button value=加入到频道 onclick=style="color: rgb(255,0,255)">"window.external.showbrowserui('privacysettings',null)">

     

    //不缓存

    style="border-right: rgb(138,138,138) 1px solid; padding-right: 4px; border-top: rgb(138,138,138) 1px solid; padding-left: 4px; font-size: 12px; padding-bottom: 4px; margin: 4px; overflow: auto; border-left: rgb(138,138,138) 1px solid; padding-top: 4px; border-bottom: rgb(138,138,138) 1px solid; font-family: courier new; background-color: rgb(238,238,238)"><meta http-equiv=style="color: rgb(255,0,255)">"pragma" content=style="color: rgb(255,0,255)">"no-cache">


    <meta http-equiv=style="color: rgb(255,0,255)">"cache-control" content=style="color: rgb(255,0,255)">"no-cache, must-revalidate">


    <meta http-equiv=style="color: rgb(255,0,255)">"expires" content=style="color: rgb(255,0,255)">"0">

     


    //正则匹配 size=2>

    style="border-right: rgb(138,138,138) 1px solid; padding-right: 4px; border-top: rgb(138,138,138) 1px solid; padding-left: 4px; font-size: 12px; padding-bottom: 4px; margin: 4px; overflow: auto; border-left: rgb(138,138,138) 1px solid; padding-top: 4px; border-bottom: rgb(138,138,138) 1px solid; font-family: courier new; background-color: rgb(238,238,238)">size=2>匹配中文字符的正则表达式: [\u4e00-\u9fa5]
    匹配双字节字符(包括汉字在内):[^\x00-\xff]


    匹配空行的正则表达式:\n[\s| ]*\r


    匹配html标记的正则表达式:/<(.*)>.*<\/\1>|<(.*) \/>/ 


    匹配首尾空格的正则表达式:(^\s*)|(\s*$)(像vbscript那样的trim函数)


    匹配email地址的正则表达式:\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*


    匹配网址url的正则表达式:http:style="color: rgb(0,128,0)">//([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?


    以下是例子:
    利用正则表达式限制网页表单里的文本框输入内容:
    用正则表达式限制只能输入中文:onkeyup=style="color: rgb(255,0,255)">"value=value.replace(/[^\u4e00-\u9fa5]/g,'')" onbeforepaste=style="color: rgb(255,0,255)">"clipboarddata.setdata('text',clipboarddata.getdata('text').replace(/[^\u4e00-\u9fa5]/g,''))"


    1.用正则表达式限制只能输入全角字符: onkeyup=style="color: rgb(255,0,255)">"value=value.replace(/[^\uff00-\uffff]/g,'')" onbeforepaste=style="color: rgb(255,0,255)">"clipboarddata.setdata('text',clipboarddata.getdata('text').replace(/[^\uff00-\uffff]/g,''))"


    2.用正则表达式限制只能输入数字:onkeyup=style="color: rgb(255,0,255)">"value=value.replace(/[^\d]/g,'') "onbeforepaste=style="color: rgb(255,0,255)">"clipboarddata.setdata('text',clipboarddata.getdata('text').replace(/[^\d]/g,''))"


    3.用正则表达式限制只能输入数字和英文:onkeyup=style="color: rgb(255,0,255)">"value=value.replace(/[\w]/g,'') "onbeforepaste=style="color: rgb(255,0,255)">"clipboarddata.setdata('text',clipboarddata.getdata('text').replace(/[^\d]/g,''))"

    //消除图像工具栏

    style="border-right: rgb(138,138,138) 1px solid; padding-right: 4px; border-top: rgb(138,138,138) 1px solid; padding-left: 4px; font-size: 12px; padding-bottom: 4px; margin: 4px; overflow: auto; border-left: rgb(138,138,138) 1px solid; padding-top: 4px; border-bottom: rgb(138,138,138) 1px solid; font-family: courier new; background-color: rgb(238,238,238)"><img src=style="color: rgb(255,0,255)">"mypicture.jpg" height=style="color: rgb(255,0,255)">"100px" width=style="color: rgb(255,0,255)">"100px" galleryimg=style="color: rgb(255,0,255)">"false"
    or
    <head>


    <meta http-equiv=style="color: rgb(255,0,255)">"imagetoolbar" content=style="color: rgb(255,0,255)">"no">
    </head>

     

    //无提示关闭

    style="border-right: rgb(138,138,138) 1px solid; padding-right: 4px; border-top: rgb(138,138,138) 1px solid; padding-left: 4px; font-size: 12px; padding-bottom: 4px; margin: 4px; overflow: auto; border-left: rgb(138,138,138) 1px solid; padding-top: 4px; border-bottom: rgb(138,138,138) 1px solid; font-family: courier new; background-color: rgb(238,238,238)">style="color: rgb(0,0,255)">function close()
    {
     style="color: rgb(0,0,255)">var ua=navigator.useragent


     style="color: rgb(0,0,255)">var ie=navigator.appname==style="color: rgb(255,0,255)">"microsoft internet explorer"?style="color: rgb(0,0,255)">true:false
     style="color: rgb(0,0,255)">if(ie)
     {


          style="color: rgb(0,0,255)">var ieversion=parsefloat(ua.substring(ua.indexof(style="color: rgb(255,0,255)">"msie ")+5,ua.indexof(style="color: rgb(255,0,255)">";",ua.indexof(style="color: rgb(255,0,255)">"msie "))))
      style="color: rgb(0,0,255)">if(ieversion< 5.5)
      {


       style="color: rgb(0,0,255)">var str  = '<object id=notipclose classid=style="color: rgb(255,0,255)">"clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11">'


           str += '<param name=style="color: rgb(255,0,255)">"command" value=style="color: rgb(255,0,255)">"close"></object>';


           document.body.insertadjacenthtml(style="color: rgb(255,0,255)">"beforeend", str);


           document.all.notipclose.click();


      }
          else
      {


           window.opener =style="color: rgb(0,0,255)">null;


           window.close();


          }
       }
     else


     {
      window.close()
       }
    }

    //取得控件得绝对位置(1)

    style="border-right: rgb(138,138,138) 1px solid; padding-right: 4px; border-top: rgb(138,138,138) 1px solid; padding-left: 4px; font-size: 12px; padding-bottom: 4px; margin: 4px; overflow: auto; border-left: rgb(138,138,138) 1px solid; padding-top: 4px; border-bottom: rgb(138,138,138) 1px solid; font-family: courier new; background-color: rgb(238,238,238)"><script language=style="color: rgb(255,0,255)">"javascript"
    style="color: rgb(0,0,255)">function getoffset(e)


     var t=e.offsettop; 


     style="color: rgb(0,0,255)">var l=e.offsetleft; 


     while(e=e.offsetparent)


     { 
      t+=e.offsettop; 


      l+=e.offsetleft; 
     } 
     style="color: rgb(0,0,255)">var rec = style="color: rgb(0,0,255)">new style="color: rgb(255,0,0)">array(1);


     rec[0]  = t;
     rec[1] = l;


     return rec


    </script>

    //获得控件的绝对位置(2)

    style="border-right: rgb(138,138,138) 1px solid; padding-right: 4px; border-top: rgb(138,138,138) 1px solid; padding-left: 4px; font-size: 12px; padding-bottom: 4px; margin: 4px; overflow: auto; border-left: rgb(138,138,138) 1px solid; padding-top: 4px; border-bottom: rgb(138,138,138) 1px solid; font-family: courier new; background-color: rgb(238,238,238)">orect = obj.getboundingclientrect();


    orect.left
    orect.

    //最小化,最大化,关闭

    style="border-right: rgb(138,138,138) 1px solid; padding-right: 4px; border-top: rgb(138,138,138) 1px solid; padding-left: 4px; font-size: 12px; padding-bottom: 4px; margin: 4px; overflow: auto; border-left: rgb(138,138,138) 1px solid; padding-top: 4px; border-bottom: rgb(138,138,138) 1px solid; font-family: courier new; background-color: rgb(238,238,238)"><object id=min classid=style="color: rgb(255,0,255)">"clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"


    <param name=style="color: rgb(255,0,255)">"command" value=style="color: rgb(255,0,255)">"minimize"></object> 


    <object id=max classid=style="color: rgb(255,0,255)">"clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"


    <param name=style="color: rgb(255,0,255)">"command" value=style="color: rgb(255,0,255)">"maximize"></object> 


    <object id=close classid=style="color: rgb(255,0,255)">"clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11"


    <param name=style="color: rgb(255,0,255)">"command" value=style="color: rgb(255,0,255)">"close"></object> 


    <input type=button value=最小化 onclick=min.click()> 


    <input type=button value=最大化 onclick=max.click()> 


    <input type=button value=关闭 onclick=close.click()> 

     

    //光标停在文字最后

    style="border-right: rgb(138,138,138) 1px solid; padding-right: 4px; border-top: rgb(138,138,138) 1px solid; padding-left: 4px; font-size: 12px; padding-bottom: 4px; margin: 4px; overflow: auto; border-left: rgb(138,138,138) 1px solid; padding-top: 4px; border-bottom: rgb(138,138,138) 1px solid; font-family: courier new; background-color: rgb(238,238,238)"><script language=style="color: rgb(255,0,255)">"javascript">
    style="color: rgb(0,0,255)">function cc()
    {
     style="color: rgb(0,0,255)">var e = event.srcelement;


     style="color: rgb(0,0,255)">var r =e.createtextrange();


     r.movestart('character',e.value.length);
     r.collapse(style="color: rgb(0,0,255)">true);
     r.select();
    }


    </script>


    <input type=text name=text1 value=style="color: rgb(255,0,255)">"123" onfocus=style="color: rgb(255,0,255)">"cc()">

    //页面进入和退出的特效

    style="border-right: rgb(138,138,138) 1px solid; padding-right: 4px; border-top: rgb(138,138,138) 1px solid; padding-left: 4px; font-size: 12px; padding-bottom: 4px; margin: 4px; overflow: auto; border-left: rgb(138,138,138) 1px solid; padding-top: 4px; border-bottom: rgb(138,138,138) 1px solid; font-family: courier new; background-color: rgb(238,238,238)">进入页面<meta http-equiv=style="color: rgb(255,0,255)">"page-enter" content=style="color: rgb(255,0,255)">"revealtrans(duration=x, transition=y)">


    推出页面<meta http-equiv=style="color: rgb(255,0,255)">"page-exit" content=style="color: rgb(255,0,255)">"revealtrans(duration=x, transition=y)"


    这个是页面被载入和调出时的一些特效。duration表示特效的持续时间,以秒为单位。transition表示使
    用哪种特效,取值为1-23:


      0 矩形缩小 
      1 矩形扩大 
      2 圆形缩小


      3 圆形扩大 
      4 下到上刷新 
      5 上到下刷新


      6 左到右刷新 
      7 右到左刷新 
      8 竖百叶窗


      9 横百叶窗 
      10 错位横百叶窗 
      11 错位竖百叶窗


      12 点扩散 
      13 左右到中间刷新 
      14 中间到左右刷新


      15 中间到上下
      16 上下到中间 
      17 右下到左上


      18 右上到左下 
      19 左上到右下 
      20 左下到右上


      21 横条 
      22 竖条 
      23 

    //网页是否被检索

    style="border-right: rgb(138,138,138) 1px solid; padding-right: 4px; border-top: rgb(138,138,138) 1px solid; padding-left: 4px; font-size: 12px; padding-bottom: 4px; margin: 4px; overflow: auto; border-left: rgb(138,138,138) 1px solid; padding-top: 4px; border-bottom: rgb(138,138,138) 1px solid; font-family: courier new; background-color: rgb(238,238,238)"><meta name=style="color: rgb(255,0,255)">"robots" content=style="color: rgb(255,0,255)">"属性值">
      其中属性值有以下一些:
      属性值为style="color: rgb(255,0,255)">"all": 文件将被检索,且页上链接可被查询;


      属性值为style="color: rgb(255,0,255)">"none": 文件不被检索,而且不查询页上的链接;


      属性值为"index": 文件将被检索;


      属性值为"follow": 查询页上的链接;


      属性值为style="color: rgb(255,0,255)">"noindex": 文件不检索,但可被查询链接;


      属性值为"nofollow"

     


    //打印分页

    style="border-right: rgb(138,138,138) 1px solid; padding-right: 4px; border-top: rgb(138,138,138) 1px solid; padding-left: 4px; font-size: 12px; padding-bottom: 4px; margin: 4px; overflow: auto; border-left: rgb(138,138,138) 1px solid; padding-top: 4px; border-bottom: rgb(138,138,138) 1px solid; font-family: courier new; background-color: rgb(238,238,238)"><p  style=style="color: rgb(255,0,255)">"page-break-after:always">page1</p>  


    <p  style=style="color: rgb(255,0,255)">"page-break-after:always">page2</p>  

     


    //设置打印

    style="border-right: rgb(138,138,138) 1px solid; padding-right: 4px; border-top: rgb(138,138,138) 1px solid; padding-left: 4px; font-size: 12px; padding-bottom: 4px; margin: 4px; overflow: auto; border-left: rgb(138,138,138) 1px solid; padding-top: 4px; border-bottom: rgb(138,138,138) 1px solid; font-family: courier new; background-color: rgb(238,238,238)"><object id=style="color: rgb(255,0,255)">"factory" style=style="color: rgb(255,0,255)">"display:none" viewastext


      classid=style="color: rgb(255,0,255)">"clsid:1663ed61-23eb-11d2-b92f-008048fdd814"


      codebase="http:style="color: rgb(0,128,0)">//www.meadroid.com/scriptx/scriptx.cab#version=5,60,0,360"


    ></object>


    <input type=button value=页面设置 onclick=style="color: rgb(255,0,255)">"factory.printing.pagesetup()">


    <input type=button value=打印预览 onclick=style="color: rgb(255,0,255)">"factory.printing.preview()">
     


    <script language=javascript>
    style="color: rgb(0,0,255)">function window.onload()
    {


       style="color: rgb(0,128,0)">// -- advanced features


       factory.printing.setmarginmeasure(2) style="color: rgb(0,128,0)">// measure margins in inches


       factory.printing.setpagerange(style="color: rgb(0,0,255)">false, 1, 3) style="color: rgb(0,128,0)">// need pages from 1 to 3


       factory.printing.printer = style="color: rgb(255,0,255)">"hp deskjet 870c"


       factory.printing.copies = 2


       factory.printing.collate = true


       factory.printing.papersize = style="color: rgb(255,0,255)">"a4"


       factory.printing.papersource = style="color: rgb(255,0,255)">"manual feed"


       style="color: rgb(0,128,0)">// -- basic features


       factory.printing.header = style="color: rgb(255,0,255)">"居左显示&b居中显示&b居右显示页码,第&p页/共&p页"


       factory.printing.footer = style="color: rgb(255,0,255)">"(自定义页脚)"


       factory.printing.portrait = false


       factory.printing.leftmargin = 0.75


       factory.printing.topmargin = 1.5


       factory.printing.rightmargin = 0.75


       factory.printing.bottommargin = 1.5
    }


    function print(frame) {


      factory.printing.print(style="color: rgb(0,0,255)">true, frame) style="color: rgb(0,128,0)">// print with prompt
    }


    </script>
    <input type=button value=style="color: rgb(255,0,255)">"打印本页" onclick=style="color: rgb(255,0,255)">"factory.printing.print(false)">


    <input type=button value=style="color: rgb(255,0,255)">"页面设置" onclick=style="color: rgb(255,0,255)">"factory.printing.pagesetup()">


    <input type=button value=style="color: rgb(255,0,255)">"打印预览" onclick=style="color: rgb(255,0,255)">"factory.printing.preview()"><br>


    <a href="http:style="color: rgb(0,128,0)">//www.meadroid.com/scriptx/docs/printdoc.htm?static"  target=_blank>具体使用手册,更多信息,点这里</a>


     

    //自带的打印预览

    style="border-right: rgb(138,138,138) 1px solid; padding-right: 4px; border-top: rgb(138,138,138) 1px solid; padding-left: 4px; font-size: 12px; padding-bottom: 4px; margin: 4px; overflow: auto; border-left: rgb(138,138,138) 1px solid; padding-top: 4px; border-bottom: rgb(138,138,138) 1px solid; font-family: courier new; background-color: rgb(238,238,238)">webbrowser.execwb(1,1) 打开 


    web.execwb(2,1) 关闭现在所有的ie窗口,并打开一个新窗口 


    web.execwb(4,1) 保存网页 
    web.execwb(6,1) 打印 


    web.execwb(7,1) 打印预览 
    web.execwb(8,1) 打印页面设置 


    web.execwb(10,1) 查看页面属性 


    web.execwb(15,1) 好像是撤销,有待确认 
    web.execwb(17,1) 全选 


    web.execwb(22,1) 刷新 
    web.execwb(45,1) 关闭窗体无提示 


    <style media=print> 


    .noprint{display:none;}<!--用本样式在打印时隐藏非打印项目--> 


    .pagenext{page-break-after: always;}<!--控制分页--> 


    </style> 
    <object  id=style="color: rgb(255,0,255)">"webbrowser"  width=0  height=0  classid=style="color: rgb(255,0,255)">"clsid:8856f961-340a-11d0-a96b-00c04fd705a2">    


    </object>    
     


    <center class=style="color: rgb(255,0,255)">"noprint" >


    <input type=button value=打印 onclick=document.all.webbrowser.execwb(6,1)> 


    <input type=button value=直接打印 onclick=document.all.webbrowser.execwb(6,6)> 


    <input type=button value=页面设置 onclick=document.all.webbrowser.execwb(8,1)> 


    </p> 


    <p> <input type=button value=打印预览 onclick=document.all.webbrowser.execwb(7,1)> 


    </center>

    //去掉打印时的页眉页脚

    style="border-right: rgb(138,138,138) 1px solid; padding-right: 4px; border-top: rgb(138,138,138) 1px solid; padding-left: 4px; font-size: 12px; padding-bottom: 4px; margin: 4px; overflow: auto; border-left: rgb(138,138,138) 1px solid; padding-top: 4px; border-bottom: rgb(138,138,138) 1px solid; font-family: courier new; background-color: rgb(238,238,238)"><script  language=style="color: rgb(255,0,255)">"javascript">  
    style="color: rgb(0,0,255)">var hkey_root,hkey_path,hkey_key;


    hkey_root="hkey_current_user";


    hkey_path=style="color: rgb(255,0,255)">"\\software\\microsoft\\internet explorer\\pagesetup\\";


    //设置网页打印的页眉页脚为空
    style="color: rgb(0,0,255)">function pagesetup_null()
    {


     try
     {


             style="color: rgb(0,0,255)">var wsh=style="color: rgb(0,0,255)">new style="color: rgb(255,0,0)">activexobject(style="color: rgb(255,0,255)">"wscript.shell");


      hkey_key="header";


      wsh.regwrite(hkey_root+hkey_path+hkey_key,style="color: rgb(255,0,255)">"");
      hkey_key=style="color: rgb(255,0,255)">"footer";


      wsh.regwrite(hkey_root+hkey_path+hkey_key,style="color: rgb(255,0,255)">"");
     }
     style="color: rgb(0,0,255)">catch(e){}
    }
    style="color: rgb(0,128,0)">//设置网页打印的页眉页脚为默认值
    style="color: rgb(0,0,255)">function  pagesetup_default()


    {  
     try
     {
      style="color: rgb(0,0,255)">var wsh=style="color: rgb(0,0,255)">new style="color: rgb(255,0,0)">activexobject(style="color: rgb(255,0,255)">"wscript.shell");


      hkey_key="header";


      wsh.regwrite(hkey_root+hkey_path+hkey_key,style="color: rgb(255,0,255)">"&w&b页码,&p/&p");


      hkey_key="footer";


      wsh.regwrite(hkey_root+hkey_path+hkey_key,style="color: rgb(255,0,255)">"&u&b&d");
     }


     catch(e){}
    }


    </script>
    <input type=style="color: rgb(255,0,255)">"button" value=style="color: rgb(255,0,255)">"清空页码" onclick=pagesetup_null()>


    <input type=style="color: rgb(255,0,255)">"button" value=style="color: rgb(255,0,255)">"恢复页码" onclick=pagesetup_default()>

    //浏览器验证

    size=2>

    style="border-right: rgb(138,138,138) 1px solid; padding-right: 4px; border-top: rgb(138,138,138) 1px solid; padding-left: 4px; font-size: 12px; padding-bottom: 4px; margin: 4px; overflow: auto; border-left: rgb(138,138,138) 1px solid; padding-top: 4px; border-bottom: rgb(138,138,138) 1px solid; font-family: courier new; background-color: rgb(238,238,238)">style="color: rgb(0,0,255)">functionsize=2> checkbrowser()

       style="color: rgb(0,0,255)">this.ver=navigator.appversion 


       style="color: rgb(0,0,255)">this.dom=document.getelementbyid?1:0 


       this.ie6=(style="color: rgb(0,0,255)">this.ver.indexof(style="color: rgb(255,0,255)">"msie 6")>-1 && style="color: rgb(0,0,255)">this.dom)?1:0; 


       this.ie5=(style="color: rgb(0,0,255)">this.ver.indexof(style="color: rgb(255,0,255)">"msie 5")>-1 && style="color: rgb(0,0,255)">this.dom)?1:0; 


       style="color: rgb(0,0,255)">this.ie4=(document.all && !style="color: rgb(0,0,255)">this.dom)?1:0; 


       this.ns5=(style="color: rgb(0,0,255)">this.dom && parseint(style="color: rgb(0,0,255)">this.ver) >= 5) ?1:0; 


       style="color: rgb(0,0,255)">this.ns4=(document.layers && !style="color: rgb(0,0,255)">this.dom)?1:0; 


       this.mac=(style="color: rgb(0,0,255)">this.ver.indexof('mac') > -1) ?1:0; 


       style="color: rgb(0,0,255)">this.ope=(navigator.useragent.indexof('opera')>-1); 


       this.ie=(style="color: rgb(0,0,255)">this.ie6 || style="color: rgb(0,0,255)">this.ie5 || style="color: rgb(0,0,255)">this.ie4) 
       style="color: rgb(0,0,255)">this.ns=(style="color: rgb(0,0,255)">this.ns4 || style="color: rgb(0,0,255)">this.ns5) 
       style="color: rgb(0,0,255)">this.bw=(style="color: rgb(0,0,255)">this.ie6 || style="color: rgb(0,0,255)">this.ie5 || style="color: rgb(0,0,255)">this.ie4 || style="color: rgb(0,0,255)">this.ns5 || style="color: rgb(0,0,255)">this.ns4 || 
    style="color: rgb(0,0,255)">this.mac || style="color: rgb(0,0,255)">this.ope) 
       style="color: rgb(0,0,255)">this.nbw=(!style="color: rgb(0,0,255)">this.bw) 
       style="color: rgb(0,0,255)">return style="color: rgb(0,0,255)">this;
    }

    //计算内容宽和高

    style="border-right: rgb(138,138,138) 1px solid; padding-right: 4px; border-top: rgb(138,138,138) 1px solid; padding-left: 4px; font-size: 12px; padding-bottom: 4px; margin: 4px; overflow: auto; border-left: rgb(138,138,138) 1px solid; padding-top: 4px; border-bottom: rgb(138,138,138) 1px solid; font-family: courier new; background-color: rgb(238,238,238)">size=2><script  language=style="color: rgb(255,0,255)">"javascript">  
    style="color: rgb(0,0,255)">function  test(obj)  


    {  
           style="color: rgb(0,0,255)">var  range  =  obj.createtextrange();  


           alert(style="color: rgb(255,0,255)">"内容区宽度:  "  +  range.boundingwidth    


                                                     +  style="color: rgb(255,0,255)">"px\r\n内容区高度:  "  +  range.boundingheight  +  style="color: rgb(255,0,255)">"px");  


                 


    }  
    </script>  
    <body>  


    <textarea id=style="color: rgb(255,0,255)">"txt" height=style="color: rgb(255,0,255)">"150">sdf</textarea><input  type=style="color: rgb(255,0,255)">"button"
      value=style="color: rgb(255,0,255)">"计算内容宽度"  onclick=style="color: rgb(255,0,255)">"test(txt)">  


    </body>

    //无模式的提示框

    style="border-right: rgb(138,138,138) 1px solid; padding-right: 4px; border-top: rgb(138,138,138) 1px solid; padding-left: 4px; font-size: 12px; padding-bottom: 4px; margin: 4px; overflow: auto; border-left: rgb(138,138,138) 1px solid; padding-top: 4px; border-bottom: rgb(138,138,138) 1px solid; font-family: courier new; background-color: rgb(238,238,238)">style="color: rgb(0,0,255)">function modelessalert(msg)
    {


       window.showmodelessdialog(style="color: rgb(255,0,255)">"""+escape(msg)+style="color: rgb(255,0,255)">"\");window.close();",style="color: rgb(255,0,255)">"",
    style="color: rgb(255,0,255)">"status:no;resizable:no;help:no;dialogheight:height:30px;dialogheight:40px;");


    }

     

    //屏蔽按键

    style="border-right: rgb(138,138,138) 1px solid; padding-right: 4px; border-top: rgb(138,138,138) 1px solid; padding-left: 4px; font-size: 12px; padding-bottom: 4px; margin: 4px; overflow: auto; border-left: rgb(138,138,138) 1px solid; padding-top: 4px; border-bottom: rgb(138,138,138) 1px solid; font-family: courier new; background-color: rgb(238,238,238)"><html>


    <head>
      <meta http-equiv=style="color: rgb(255,0,255)">"content-type" content=style="color: rgb(255,0,255)">"text/html; charset=gb2312">


      <noscript><meta http-equiv=style="color: rgb(255,0,255)">"refresh" content=style="color: rgb(255,0,255)">"0;url=about:noscript"></noscript>


      <title>屏蔽鼠标右键、ctrl+n、shift+f10、alt+f4、f11、f5刷新、退格键</title>


    </head>
    <body>
    <script language=style="color: rgb(255,0,255)">"javascript"><!--


      style="color: rgb(0,128,0)">//屏蔽鼠标右键、ctrl+n、shift+f10、f11、f5刷新、退格键


      style="color: rgb(0,128,0)">//author: meizz(梅花雨) 2002-6-18


    style="color: rgb(0,0,255)">function document.oncontextmenu(){event.returnvalue=style="color: rgb(0,0,255)">false;}style="color: rgb(0,128,0)">//屏蔽鼠标右键
    style="color: rgb(0,0,255)">function window.onhelp(){style="color: rgb(0,0,255)">return style="color: rgb(0,0,255)">falsestyle="color: rgb(0,128,0)">//屏蔽f1帮助
    style="color: rgb(0,0,255)">function document.onkeydown()
    {


      style="color: rgb(0,0,255)">if ((window.event.altkey)&&


          ((window.event.keycode==37)||   style="color: rgb(0,128,0)">//屏蔽 alt+ 方向键 ←


           (window.event.keycode==39)))   style="color: rgb(0,128,0)">//屏蔽 alt+ 方向键 →


      {
         alert(style="color: rgb(255,0,255)">"不准你使用alt+方向键前进或后退网页!");


         event.returnvalue=style="color: rgb(0,0,255)">false;
      }


         style="color: rgb(0,128,0)">/* 注:这还不是真正地屏蔽 alt+ 方向键,


         因为 alt+ 方向键弹出警告框时,按住 alt 键不放,


         用鼠标点掉警告框,这种屏蔽方法就失效了。以后若


         有哪位高手有真正屏蔽 alt 键的方法,请告知。*/


      style="color: rgb(0,0,255)">if ((event.keycode==8)  ||                 style="color: rgb(0,128,0)">//屏蔽退格删除键


          (event.keycode==116)||                 style="color: rgb(0,128,0)">//屏蔽 f5 刷新键


          (event.ctrlkey && event.keycode==82)){ style="color: rgb(0,128,0)">//ctrl + r


         event.keycode=0;


         event.returnvalue=style="color: rgb(0,0,255)">false;
         }


      style="color: rgb(0,0,255)">if (event.keycode==122){event.keycode=0;event.returnvalue=style="color: rgb(0,0,255)">false;}  style="color: rgb(0,128,0)">//屏蔽f11
      style="color: rgb(0,0,255)">if (event.ctrlkey && event.keycode==78) event.returnvalue=style="color: rgb(0,0,255)">false;   style="color: rgb(0,128,0)">//屏蔽 ctrl+n
      style="color: rgb(0,0,255)">if (event.shiftkey && event.keycode==121)event.returnvalue=style="color: rgb(0,0,255)">false;  style="color: rgb(0,128,0)">//屏蔽 shift+f10
      style="color: rgb(0,0,255)">if (window.event.srcelement.tagname == style="color: rgb(255,0,255)">"a" && window.event.shiftkey) 


          window.event.returnvalue = style="color: rgb(0,0,255)">false;             style="color: rgb(0,128,0)">//屏蔽 shift 加鼠标左键新开一网页


      style="color: rgb(0,0,255)">if ((window.event.altkey)&&(window.event.keycode==115))             style="color: rgb(0,128,0)">//屏蔽alt+f4
      {


          window.showmodelessdialog(style="color: rgb(255,0,255)">"about:blank",style="color: rgb(255,0,255)">"",style="color: rgb(255,0,255)">"dialogwidth:1px;dialogheight:1px");


          style="color: rgb(0,0,255)">return style="color: rgb(0,0,255)">false;
      }
    }


    </script>
    屏蔽鼠标右键、ctrl+n、shift+f10、alt+f4、f11、f5刷新、退格键


    </body>
    </html>