Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Copy Text in Captivate using Javascript

Explorer ,
Mar 26, 2018 Mar 26, 2018

Hello all,

I am using Captivate 10. I am wanting to do one of any of the following:

1. Press a button to copy a variables value from captivate to the clipboard

2. Press a button copy a SmartShape's text to the clipboard

It doesn't matter which one it comes from, just so long as I can get the desired text into the clipboard. This is something I've been trying to work out on my own to no avail. If someone could point me in the right direction or give me some advice on how I might go about doing this, I would greatly appreciate it!

601
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Mar 26, 2018 Mar 26, 2018

If using HTML5, can try something like this:

var myValue = window.cpAPIInterface.getVariableValue("tempX");

function copyVal(val)

{

     var inpt = document.createElement('input'); // create an input element

     document.body.appendChild(inpt); //append it to the dom

     inpt.value = val; // set its value based on passed parameter

     inpt.select(); // select

     document.execCommand('copy',false); // execute copy cmd

     inpt.remove(); // remove element

}

copyVal(myValue); // call function and pass

...
Translate
Engaged ,
Mar 26, 2018 Mar 26, 2018

If using HTML5, can try something like this:

var myValue = window.cpAPIInterface.getVariableValue("tempX");

function copyVal(val)

{

     var inpt = document.createElement('input'); // create an input element

     document.body.appendChild(inpt); //append it to the dom

     inpt.value = val; // set its value based on passed parameter

     inpt.select(); // select

     document.execCommand('copy',false); // execute copy cmd

     inpt.remove(); // remove element

}

copyVal(myValue); // call function and pass your var value

There is no error checking here, which may present a usability issue. You would need to test this cross-broswer/platform/mobile. I have no idea about security issues with this approach.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 27, 2018 Mar 27, 2018

Awesome! I really appreciate it. This for sure gave me exactly what I was looking for. Thank you so much!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Mar 27, 2018 Mar 27, 2018
LATEST

Glad it worked out for you.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Help resources