当前位置: 代码迷 >> Web前端 >> IE FF 上的复制 ctrl+c
  详细解决方案

IE FF 上的复制 ctrl+c

热度:683   发布时间:2012-10-25 10:58:57.0
IE FF 下的复制 ctrl+c

	function copyToClipboard(txt) {
			if(window.clipboardData) { 
				window.clipboardData.clearData(); 
				window.clipboardData.setData("Text",txt);  
			} else if(navigator.userAgent.indexOf("Opera")!= -1) { 
				window.location = txt; 
			} else if (window.netscape) { 
			try { 
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
			} catch (e) { 
				alert("您的firefox安全限制限制您进行剪贴板操作,请在新窗口的地址栏里输入'about:config'然后找到'signed.applets.codebase_principal_support'设置为true'之后"); 
				return false; 
			} 
			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); 
			} 
		} 		
		
?
  相关解决方案