查看效果:js双击复制支持火狐
火狐js双击复制内容代码如下:
function copy(copycontent){
if(window.clipboarddata){
window.clipboarddata.cleardata();
window.clipboarddata.setdata(text, copycontent);
}else if(navigator.useragent.indexof(opera) != -1){
window.location = copycontent;
}else if (window.netscape){
try{
netscape.security.privilegemanager.enableprivilege(universalxpconnect);
}catch (e){
alert(您的当前浏览器设置已关闭此功能!请按以下步骤开启此功能!\n新开一个浏览器,在浏览器地址栏输入'about:config'并回车。\n然后找
到'signed.applets.codebase_principal_support'项,双击后设置为'true'。\n声明:本功能不会危极您计算机或数据的安全!);
}
var clip = components.classes['@mozilla.org/widget/clipboard;1'].createinstance(components.interfaces.nsiclipboard);
if (!clip) return false;
var trans = components.classes['@mozilla.org/widget/transferable;1'].createinstance(components.interfaces.nsitransferable);
if (!trans) return false;
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 = copycontent;
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);
}
return true;
}
双击复制textarea内容,举例如下:我这里有jquery的引入。
<script language=javascript src=../js/jquery-1.4.4.min.js></script>
<script language=javascript>
$(function(){
$(textarea[name='other']).dblclick(function(){//双击复制textarea name=other里面的内容http://%77%77%77%2e%66网站制作%6f学习网%72%61%73%70%2e%63%6e
if(copy($.trim($(this).val())))alert(复制成功!);
});
});
</script>
2025国考·省考课程试听报名