Send the Ajax response to clipboard (FF:windows)
My from submission is returning a block of text that i would like sent directly to the system's clipboard. Users are on FF3.6x thx开发者_开发知识库
Hi you can use following function:
function copy_to_clipboard(text)
{
if(window.clipboardData)
{
window.clipboardData.setData('text',text);
}
else
{
var clipboarddiv=document.getElementById('divclipboardswf');
if(clipboarddiv==null)
{
clipboarddiv=document.createElement('div');
clipboarddiv.setAttribute("name", "divclipboardswf");
clipboarddiv.setAttribute("id", "divclipboardswf");
document.body.appendChild(clipboarddiv);
}
clipboarddiv.innerHTML='<embed src="clipboard.swf" FlashVars="clipboard='+
encodeURIComponent(text)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
}
alert('The text is copied to your clipboard...');
return false;
}
Further info: How do I copy to the clipboard in JavaScript?
and thanks to Andreas Grech
精彩评论