XF 2.0 I could not run this button

Emre

Well-known member
Hi, I will add a button for bbCode code shares. But I could not work the button.

for example;
2018-04-10_10-17-06.webp

I want to select the button code content and copy it automatically.
I used it like this.
CSS:
<div style="float:right;"><input type="image" value="Kopyala" src="/styles/default/xenforo/tseckopyala.png" /></div>

javascript code;
JavaScript:
<script>
function getData(element)
{
if (document.body.createTextRange) {
var range = document.body.createTextRange();
range.moveToElementText(element);
range.select();
} else if (window.getSelection) {
var selection = window.getSelection();
var range = document.createRange();
range.selectNodeContents(element);
selection.removeAllRanges();
selection.addRange(range);
}
}
</script>
Actually I want to do exactly the button used in google translate.
Thanks for your help!
 
Should it be this way?
JavaScript:
function copyText(text){
  function selectElementText(element) {
    if (document.selection) {
      var range = document.body.createTextRange();
      range.moveToElementText(element);
      range.select();
    } else if (window.getSelection) {
      var range = document.createRange();
      range.selectNode(element);
      window.getSelection().removeAllRanges();
      window.getSelection().addRange(range);
    }
  }
  var element = document.createElement('DIV');
  element.textContent = text;
  document.body.appendChild(element);
  selectElementText(element);
  document.execCommand('copy');
  element.remove();
}

var txt = document.getElementById('txt');
var btn = document.getElementById('btn');
btn.addEventListener('click', function(){
  copyText(txt.value);
})
:rolleyes:
 
Back
Top Bottom