window对象的属性---->2

•(*)screen对象,屏幕的信息
             alert("分辨率:" + screen.width + "*" + screen.height);
                 if (screen.width < 1024 || screen.height < 768) {
                        alert("分辨率太低!");
                  }
clipboardData对象,对粘贴板的操作。(也是window的一个属性)
                  clearData("Text")清空粘贴板;
                  getData("Text")读取粘贴板的值,返回值为粘贴板中的内容;
                  setData("Text",val),设置粘贴板中的值。
案例:复制地址给友好,允许复制:
<input type="button" value="推荐给好友" onclick="clipboardData.setData('Text','推荐给你一个网站,很好玩'+location.href);alert('已经将网址放到粘贴板中,发给你的好友即可');"/>

当复制的时候body的oncopy方法被触发,直接return false就是禁止复制。<body oncopy="alert('禁止复制!');return false;"

–很多元素也有oncopy、onpaste事件:

案例:禁止粘贴帐号。
      手机号:<input type="text" value="" oncopy="alert('禁止复制');return false" /><br />
     重复手机号:<input type="text" value="" onpaste="alert('请输入');return false" />
 
在网站中复制文章的时候,为了防止那些拷贝党不添加文章来源,自动在复制的内容后添加版权声明:
 1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 2 <html xmlns="http://www.w3.org/1999/xhtml" >
 3 <head>
 4     <title></title>
 5     <script type="text/javascript">
 6         function setClip() {
 7             var text = window.clipboardData.getData("text");
 8             text = text + "转载请注明:" + window.location.href;
 9             window.clipboardData.setData("text",text);
10         }
11     </script>
12 </head>
13 <body>
14 
         //不能直接在oncopy中执行对粘贴板的操作,因此设定定时器,0.1秒以后执行(加上0.1秒延时,使整个操作得得以完成),这样就不再oncopy的执行调用栈上了。
15     <textarea id="t1" oncopy="setTimeout('setClip()',50)">
16         asdfasdfasdf
17         asdfasdfasdf
18     
19     </textarea>
20     <a href="6-history.htm">链接</a>
21 </body>
22 </html>
•history操作历史记录
          –window.history.back()后退;window.history.forward()前进。
         –也可以用window.history.go(-1)、window.history.go(1)前进
 
 1 //6-history.htm  很少用
 2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 3 <html xmlns="http://www.w3.org/1999/xhtml" >
 4 <head>
 5     <title></title>
 6 </head>
 7 <body>
 8     <input type="button" value="后退" onclick="window.history.back()" />
 9 </body>
10 </html>

 

posted @ 2013-03-23 18:41  Big.Eagle  阅读(108)  评论(0)    收藏  举报