خرید بک لینک
Hello peeps,

I have taught myself HTML and CSS code but I'm still finding JavaScript very hard to understand, now to my problem. I work for a small support group and created a stand alone webpages that has links to several other stand alone webpages. quite often we have to use the same commands in our systems so I made a webpage that would copy text to clipboard using the following code:

Code:

<body>
        <BUTTON onClick="ClipBoard(copytext);">Copy</BUTTON> <SPAN ID="copytext"> <code><i>set def sys$system TEST 99</i></CODE> </SPAN>
        <TEXTAREA ID="holdtext" STYLE="display:none;"></TEXTAREA>
        <SCRIPT LANGUAGE="JavaScript">
        function ClipBoard(ct)
                {
                holdtext.ierText = ct.ierText;
                Copied = holdtext.createTextRange();
                Copied.execCommand("Copy");
                }
        </SCRIPT>
</body>

But we have had to update the webpage and have to switch off the compatibility mode so the webpage displays properly but now this javascript doesn't work.

I did find this code which does work with the compatibility mode switched off:

Code:

var copyTextareaBtn = document.querySelector('.js-textareacopybtn');

copyTextareaBtn.addEventListener('click', function(event) {
  var copyTextarea = document.querySelector('.js-copytextarea');
  copyTextarea.select();

  try {
    var successful = document.execCommand('copy');
    var msg = successful ? 'successful' : 'unsuccessful';
    console.log('Copying text command was ' + msg);
  } catch (err) {
    console.log('Oops, unable to copy');
  }
});

with:

Code:

<p>
  <textarea class="js-copytextarea">Hello I'm some text</textarea>
</p>

<p>
  <button class="js-textareacopybtn">Copy Textarea</button>
</p>

from here

but I'm not knowledgeable enough to tweak it for use with several different text on the webpage (need up 14 commands) and also what can I swap the textarea to? Used <span> & <div> and the function doesn't work after the change.

Thank you in advance

Andy

برچسب: نویسنده: آیلین رضوانی تاريخ: شنبه 3 تير 1396 ساعت: 1:28

صفحه بندی