经常在网页上看见“复制本页网址,给你的朋友分享”之类的话,点按钮,在IE下能复制成功,而在firefox和opera等其他浏览器就不行
下面的例子使用flash(as)+javascript实现了在不同浏览器里复制的功能,这样做的好处就是规避了浏览器兼容的问题。也就是说支持firefox,IE,OPERA
下载FLASH文件:
[点击浏览该文件:_clipboard.swf]
代码如下:
|
以下为引用的内容:
〈html〉 〈head〉
〈title〉用flash+javscript实现网页上的文本复制〈/title〉
〈/head〉 〈body〉 〈script type="text/javascript" language="javascript"〉 function copyit(textit) { if (window.clipboardData) { window.clipboardData.setData("Text",textit); } else {
var flashcopier = ’’flashcopier’’; if(!document.getElementById(flashcopier)) { var divholder = document.createElement(’’div’’); divholder.id = flashcopier; document.body.appendChild(divholder); } document.getElementById(flashcopier).innerHTML = ’’’’; var divinfo = ’’〈embed src="_clipboard.swf" FlashVars="clipboard=’’+textit+’’" width="0" height="0" type="application/x-shockwave-flash"〉〈/embed〉’’; document.getElementById(flashcopier).innerHTML = divinfo; } } //copyit("")
〈/script〉 〈input type="text" value="用flash+javscript实现网页上的文本复制" id="g"〉 〈a href="javascript:copyit(document.getElementById(’’g’’).value);"〉复制一下〈/a〉 〈/body〉 〈/html〉 |