复制内容到剪切板( 兼容ie8 ff ie6)

 

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.111cn.net/ 1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>复制内容到剪切板( 兼容ie8 ff ie6)</title>
</head>

<body>
<script>
//复制内容到剪切板
function copytoclipboard(txt)
{
 if(txt==null || txt=='') {
   alert("没有选择任何内容!");
   return;
 }
 if(window.clipboarddata)
 {
  window.clipboarddata.cleardata();
  window.clipboarddata.setdata("text", txt);
 }
 else if(navigator.useragent.indexof('opera') != -1)
 {
  window.location = txt;
 }
 else
 {
   try {
     netscape.security.privilegemanager.enableprivilege("universalxpconnect");
   } catch (e) {
     alert("被浏览器拒绝!n请在浏览器地址栏输入'about:config'并回车n然后将'signed.applets.codebase_principal_support'设置为'true'");
   }
   var clip = components.classes['@mozilla.org/widget/clipboard;1'].createinstance(components.interfaces.nsiclipboard);
    if (!clip) return;
 
   var trans = components.classes['@mozilla.org/widget/transferable;1'].createinstance(components.interfaces.nsitransferable);
   if (!trans) return;
 
   trans.adddataflavor('text/unicode');
   var str = new object();
   var len = new object();
   var str = components.classes["@mozilla.org/supports-string;1"].createinstance(components.interfaces.nsisupportsstring);
   var copytext = txt;
   str.data = copytext;
   trans.settransferdata("text/unicode",str,copytext.length*2);
   var clipid = components.interfaces.nsiclipboard;
   if (!clip) return false;
   clip.setdata(trans,null,clipid.kglobalclipboard);
 }
}
</script>
</body>
</html>

时间: 2024-07-31 19:47:15

复制内容到剪切板( 兼容ie8 ff ie6)的相关文章

兼容ie8 ff ie6复制内容到剪切板

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-

简单实现兼容各大浏览器的js复制内容到剪切板_jquery

因为网站文章需要提供几个按钮,单击后实现复制文章内容到剪贴板. 在网上搜索了很多内容,发现都比较乱这里自己整理下,分享给大家 效果图如下: 之前使用的是window.clipboardData.setData,只能支持IE和火狐.360浏览器.搜狗等浏览器,都泪崩.所以,研究了ZeroClipboard,尽量使用js代码写. 使用前先引用三个东西(没有提供上传附件,这里就不提供下载地址了,很常见,大家自己找度娘吧): jquery-1.4.1.min.js    ZeroClipboard.js

js复制内容到剪切板代码

function copyweather(meintext) {  if (window.clipboardData) {   window.clipboardData.setData("Text", meintext);  }   else if (window.netscape) {    netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');    var clip = Component

兼容ie8 ff ie6获取窗口顶部与左边像素代码

 _browser_scroll_x = 0;     _browser_scroll_y = 0;     if( typeof( window.pageyoffset ) == 'number' )     {         //netscape compliant         _browser_scroll_y = window.pageyoffset;         _browser_scroll_x = window.pagexoffset;     } else if( do

JS实现复制内容到剪贴板功能兼容所有浏览器(推荐)_jquery

两天前听了一个H5的分享,会议上有一句话,非常有感触:不是你不能,而是你对自己的要求太低.很简单的一句话,相信很多事情不是大家做不到,真的是对自己的要求太低,如果对自己要求多一点,那么你取得的进步可能会更大.成长以来,很多朋友也听说到不少激励自己上进的话,但不是每个人都能一直坚持做下来,其实,这个跟自己的性格以及周围的环境都有很大关系,只能说多找方法.条件给自己鼓励,不断提高对自己的要求,才有机会获得多一点的成就. 今年下半年打算在组内建个叫『移动开发指南』的站点,在网站框架搭建过程,有一个功能

java 复制图片到剪切板

Java 如何复制图片到剪切板呢? 下面是我做的一个软件: 项目源代码见附件  这里面就有"复制图片到剪切板"功能.核心方法如下: Java代码   /***       * 复制图片到剪切板       * @param image       */       public static void setClipboardImage(JFrame frame, final Image image) {           Transferable trans = new Trans

利用jquery.zclip复制网页内容到剪切板

核心代码  代码如下 复制代码 ("input").zclip({     path: 'http://steamdev.com/zclip/js/ZeroClipboard.swf',     copy: $("p").html(),     beforeCopy:function(){         console.log("复制之前");     },     afterCopy:function(){         alert(&qu

js获取浏览器高度和宽度值(兼容ie7 ff ie6多浏览器)

代码如下 function calc_scroll_xy() {     _browser_scroll_x = 0;     _browser_scroll_y = 0;     if( typeof( window.pageyoffset ) == 'number' )     {         //netscape compliant         _browser_scroll_y = window.pageyoffset;         _browser_scroll_x = w

javascript弹层提示的复制内容剪切板功能(复制插件)

然后造轮子的路上是痛苦的, 各种兼容问题, 各种事件, 哎, 也罢, 最终也成了... 感谢 张鑫旭 - js+flash(as3)实现复制文字 让我有的思路... 看一下效果图 目前测试兼容ie6+,谷歌,火狐等...当然我是用ietester测的... 有问题直接联系我吧.. 谢谢 当前接口API:  代码如下 复制代码 /**  * 复制文字  * 突然觉得不知道用空间是对还是错...  * @todo 要做显示,隐藏的接口  * @example  *     1, 单个节点复制  *