Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

SetClipboard For Firefox

DZone's Guide to

SetClipboard For Firefox

·
Free Resource
post : 2006-01-10
update : 2006-01-10
maybe work : Firefox1.5 and Opera8.5

function setClipboard(text){
	var url = [
		'data:text/html;charset=utf-8;base64,PGJvZHk+PC9ib2',
		'R5PjxzY3JpcHQgdHlwZT0idGV4dC9qYXZhc2NyaXB0Ij4KKGZ1',
		'bmN0aW9uKGVuY29kZWQpe3ZhciBzd2ZfZGF0YSA9IFsKICdkYX',
		'RhOmFwcGxpY2F0aW9uL3gtc2hvY2t3YXZlLWZsYXNoO2Jhc2U2',
		'NCxRMWRUQjJ3JywKICdBQUFCNG5EUGdZbGpBd01qSTRNejAlMk',
		'YlMkY5JTJGZTJaZkJnYUdhV3dNRE1uNUthJywKICdrTU10TjRH',
		'ZGdaZ1NJTXdaWEZKYW01UUFFJTJCQm9iaTFCTG5uTXlDcFB6RW',
		'9oU0dJJywKICdQRnAlMkZBeHNEREJRa3BGWkRGUUZGQ2d1eVM4',
		'QXlqSTRBRVVCaXkwVndBJTNEJTNEJwpdLmpvaW4oIiIpOwpkb2',
		'N1bWVudC5ib2R5LmlubmVySFRNTCA9IFsKICc8ZW1iZWQgc3Jj',
		'PSInLHN3Zl9kYXRhLCciICcsCiAnRmxhc2hWYXJzPSJjb2RlPS',
		'csZW5jb2RlZCwnIj4nLAogJzwvZW1iZWQ+JwpdLmpvaW4oIiIp',
		'Owp9KSgi',
		base64encode( encodeURIComponent(text) + '")
  ')
	].join("");
	var tmp = document.createElement("div");
	tmp.innerHTML = [
		 ''
	].join("");
	with(tmp.style){
		position ="absolute";
		left = "-10px";
		top  = "-10px";
		visibility = "hidden";
	};
	document.body.appendChild(tmp);
	setTimeout(function(){document.body.removeChild(tmp)},1000);
	function base64encode(str){
		var Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split("");
		var c1, c2, c3;
		var buf = [];
		var len = str.length;
		var i = 0;
		while(i < len){
			c1 = str.charCodeAt(i) & 0xff;
			c2 = str.charCodeAt(i+1);
			c3 = str.charCodeAt(i+2);
			buf.push(Chars[(c1 >> 2)]);
			if(i+1 == len){
				buf.push(Chars[(c1 & 0x3) << 4],"==");
				break;
			}
			buf.push(Chars[((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4)]);
			if(i+2 == len){
				buf.push(Chars[(c2 & 0xF) << 2],"=");
				break;
			}
			buf.push(
				Chars[((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6)],
				Chars[(c3 & 0x3F)]
			);
			i+=3;
		}
		return buf.join("")
	}
}


here is demo.

just a firefox only
http://la.ma.la/misc/js/setclipboard.txt
Topics:

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}