JavaScript implements perfectly compatible multi browser replication code

  • 2020-06-03 05:47:10
  • OfStack

Share a copy of the code using JavaScript for multiple browsers, 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  Copy function code, compatible with multiple browsers </title> 
</head> 
<script language="javascript"> 
copyValue=function(strValue){ 
  if(isIE()){ 
    clipboardData.setData("Text",strValue); 
    alert(" You have successfully copied this address "); 
  }else{ 
    copy(strValue); 
    alert(" The content has been copied! "); 
  } 
} 
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="//img.jbzj.com/demoimg/200910/_clipboard.swf" FlashVars="clipboard='+text2copy+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';// Here's the key  
  document.getElementById(flashcopier).innerHTML = divinfo; 
} 
</script> 
<div class="phoinfo"> 
 Map address: <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=" copy " /> 
</div> 
</body> 
</html> 

Above is the article to share all the content, I hope you can enjoy.


Related articles: