[Tex/LaTex] Copy to clipboard using Javascript macro

copy/pastejavascriptmacros

I'm pretty inexperienced with Javascript, especially within LaTeX, so I'd like some pointers, guidance or even an MWE of my proposed "button":

I want to create a button to copy data to the system clipboard. For this I'd like to suggest using a workaround with a flash leak (don't know if it works):

function copy(str) {
   var D=document;
    if(!copy.div) { copy.div = D.createElement('div'); D.body.appendChild(copy.div);  }

flashVar = "Q1dTB3kAAAB4nKtgYI1nYOBfwMDAw8jgzPT//3975lAGBoYOdQYWhu\
SczIKk/MSiFIac1Lz0kgyG4MriktRchuLUEme41DQmBg4GGRDJ6Cc0l4l  BAibCzsDO\
CDSJgwksyRwkzuAA5AIAd7oY/w==";

copy.div.innerHTML =  '<embed src="'+flashVar+'" FlashVars="clipboard='+encodeURIComponent(str) +
    '" width="0" height="0" type="application/x-shockwave-flash"></embed>';
}

I want to use the following button which will do the copying:

\documentclass[11pt,a4paper]{standalone}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shadows}

\newcommand*\button{%
  \tikz[baseline=(key.base)]
    \node[%
      draw,
      fill=white,
      drop shadow={shadow xshift=0.25ex,shadow yshift=-0.25ex,fill=black,opacity=0.75},
      rectangle,
      rounded corners=2pt,
      inner sep=1pt,
      line width=0.5pt,
      font=\scriptsize\sffamily
    ](key) {Ctrl\strut}
  ;
    \tikz[baseline=(key.base)]
    \node[%
      draw,
      fill=white,
      drop shadow={shadow xshift=0.25ex,shadow yshift=-0.25ex,fill=black,opacity=0.75},
      rectangle,
      rounded corners=2pt,
      inner sep=1pt,
      line width=0.5pt,
      font=\scriptsize\sffamily
    ](key) {C\strut}
  ;
}

\begin{document}
\button
\end{document}

Best Answer

You have already asked the same question without the code some hours ago - maybe you could have modified it instead of posting it again.

Regarding your question:

  1. Be aware that JavaScript in PDF does not work reliably. It is often disabled for security purposes and other PDF readers than Acrobat may behave different or even lack JS support.
  2. Be sure to test with the newest Acrobat version. Adobe strengthened security recently and introduced an application sandbox. Reading the clipboard should (hopefully) be off limit / impossible as this would be an information leak (for example if you copied a password in the clipboard before). Overwriting the system clipboard may be blocked too (web browsers block it, for example).
  3. A workaround may be to write the content into a form-field in the document and asking the user to copy it manually.
Related Question