欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

javascript中clipboardData對象用法詳解

 更新時(shí)間:2015年05月13日 11:20:34   作者:永遠(yuǎn)愛好寫程序  
這篇文章主要介紹了javascript中clipboardData對象用法,詳細(xì)分析了clipboardData對象的功能及相關(guān)使用技巧,需要的朋友可以參考下

本文實(shí)例講述了javascript中clipboardData對象用法。分享給大家供大家參考。具體分析如下:

clipboardData對象  ,注意網(wǎng)頁里剪貼板到現(xiàn)在只能設(shè)置Text類型,即只能復(fù)制文本
clearData("Text")清空粘貼板
getData("Text")讀取粘貼板的值
setData("Text",val)設(shè)置粘貼板的值

當(dāng)復(fù)制的時(shí)候body的oncopy事件被觸發(fā),直接return false就是禁止復(fù)制,注意是不能復(fù)制網(wǎng)頁里的文本了
<body oncopy="alert('禁止復(fù)制!');return false;">
很多元素也有oncopy,onpaste事件

1.復(fù)制文本到剪貼板

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <title></title>
 <script type="text/javascript">
 function CopyLinkAddress() {
  clipboardData.setData("Text", "請復(fù)制網(wǎng)址到您的QQ:" + location.href);
  alert("復(fù)制成功!");
 }
 </script>
</head>
<body>
 <input type="button" value="復(fù)制網(wǎng)址" onclick="CopyLinkAddress()" />
</body>
</html>

2.禁止復(fù)制,和禁止粘貼

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <title></title>
 <script type="text/javascript">
 function CopyLinkAddress() {
  clipboardData.setData("Text", "請復(fù)制網(wǎng)址到您的QQ:" + location.href);
  alert("復(fù)制成功!");
 }
 </script>
</head>
<!--<body oncopy="alert('禁止復(fù)制');return false;">-->
<body>
 <input type="button" value="復(fù)制網(wǎng)址" onclick="CopyLinkAddress()" />
 測試復(fù)制的文本<br />
 手機(jī)號碼1:<input type="text" /><br />
 手機(jī)號碼2:<input type="text" 
 onpaste="alert('禁止粘貼,必須手工錄入!');return false;" />
</body>
</html>

3.clipboardData對象復(fù)制時(shí)添加來源

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <title></title>
 <script type="text/javascript">
 function ModifyCopyData() {
  clipboardData.setData('Text',clipboardData.getData('Text') +
   '\r\n來自Pigeon網(wǎng)站' + location.href);
 }
 </script>
</head>
<!--不能直接在oncopy中調(diào)用ModifyCopyData函數(shù)
 需設(shè)定定時(shí)器,0.1秒后執(zhí)行,這樣就不再oncopy的執(zhí)行調(diào)用堆棧上了
-->
<body oncopy="setTimeout('ModifyCopyData()',100)">
 腳本之家:www.dbjr.com.cn
</body>
</html>

希望本文所述對大家的C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論