Home > Web Front-end > JS Tutorial > JavaScript implements copy function code that is perfectly compatible with multiple browsers_javascript skills

JavaScript implements copy function code that is perfectly compatible with multiple browsers_javascript skills

WBOY
Release: 2016-05-16 16:01:52
Original
993 people have browsed it

Share a piece of code that uses JavaScript to implement the copy function. It is compatible with multiple browsers, and is compatible with IE and Firefox.

<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="http://files.jb51.net/demoimg/200910/_clipboard.swf" FlashVars="clipboard='+text2copy+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';//这里是关键 
  document.getElementById(flashcopier).innerHTML = divinfo; 
} 
</script> 
<div class="phoinfo"> 
贴图地址:<input name="txtPhotoPath" value="www.daimajiayuan.com" id="txtPhotoPath" type="text" size="65" /> 
<input type="button" name="btnCopy" id="btnCopy" onClick="copyValue('www.daimajiayuan.com');" value="复制" /> 
</div> 
</body> 
</html> 
Copy after login

The above is all the content shared with you in this article. I hope you will like it.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template