网络编程 发布日期:2025/11/16 浏览次数:1
分享一段利用 JavaScript 实现复制功能的代码,兼容多浏览器,兼容IE和火狐浏览器。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>JavaScript 复制功能代码,兼容多浏览器</title>
</head>
<script language="javascript">
copyValue=function(strValue){
if(isIE()){
clipboardData.setData("Text",strValue);
alert("您已成功复制了此地址");
}else{
copy(strValue);
alert("内容已被复制!");
}
}
function isIE(number){
if(typeof(number)!=number){
return!!document.all;
}
}
function copy(text2copy){
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="/UploadFiles/2021-04-02/_clipboard.swf">
以上所述就是本文给大家的分享的全部内容了,希望大家能够喜欢。