text-kopieren-ohne-das-es-eiin-textfeld-ist-zbd-dafuer-mit-contentEditable.php


Quell Code


<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<title>Homepage von Basti1012</title>
<style>
#copy{
  width: 400px;
  height: 400px;
  border: 1px groove gray;
  color: navy;
  text-align: center;
  box-shadow: 0 4px 8px 0 gray;
}

#copy h1 {
  color: blue;
}

#copy h2 {
  color: red;
}

#copy h3 {
  color: green;
}

#copy h4 {
  color: cyan;
}

#copy h5 {
  color: brown;
}

#copyTarget h6 {
  color: teal;
}

#paste{
  width: 400px;
  height: 400px;
  border: 1px inset skyblue;
}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> 

</head>
<body>
<div id="copy">
  <h1>Heading 1</h1>
  <h2>Heading 2</h2>
  <h3>Heading 3</h3>
  <h4>Heading 4</h4>
  <h5>Heading 5</h5>
  <h6>Heading 6</h6>
  <strong>Preserve <em>formatting</em></strong>
  <br/>
</div>

<button id="javascript">Kopiere mit Javascript</button>
<button id="jqueryclick">Kopiere mit jQuery</button>
<br><br> Hier kannst du das ergebniss testen
<div id="paste" contenteditable="true"></div>

<script>

document.getElementById("javascript").addEventListener("click", function() {
  PureJS(document.getElementById("copy"));
  alert("Text Copied to Clipboard Using Pure Javascript");
});

function PureJS(element_id) {
  element_id.setAttribute("contentEditable", true);
  element_id.setAttribute("onfocus", "document.execCommand('selectAll',false,null)");
  element_id.focus();
  document.execCommand("copy");
  element_id.removeAttribute("contentEditable");
  
}


  $("#jqueryclick").click(function() {
    query("#copy");
 

  function query(element_id) {

    $(element_id).attr("contenteditable", true)
      .select()
      .on("focus", function() {
        document.execCommand('selectAll', false, null)
      })
      .focus()
    document.execCommand("Copy");
    $(element_id).removeAttr("contenteditable");
     alert("Text Copied to Clipboard Using jQuery");
  }
});
</script>
</body>
</html>


Deprecated: Directive 'allow_url_include' is deprecated in Unknown on line 0