Skip to main content
The 2024 Developer Survey results are live! See the results
clarify comments in code
Source Link
Joachim Lous
  • 1.5k
  • 1
  • 17
  • 23

Since the new Clipboard API, this is easy in browsers that support it:

javascript: navigator.clipboard.writeText('some text from somewhere');null;

Caveat: Any alerts or prompts in your bookmarklet will cause the document to lose focus, and the clipboard API will become unavailable. In that case you need to move focus back into the document before any subsequent clipboard operations will work:

const oldFocus = document.activeElement; 
/* do popup stuff here */
oldFocus.focus(); 
/* do clipboard stuff here */

Since the new Clipboard API, this is easy in browsers that support it:

javascript: navigator.clipboard.writeText('some text from somewhere');null;

Caveat: Any alerts or prompts in your bookmarklet will cause the document to lose focus, and the clipboard API will become unavailable. In that case you need to move focus back into the document before any subsequent clipboard operations will work:

const oldFocus = document.activeElement; 
/* do popup stuff */
oldFocus.focus(); 
/* do clipboard stuff */

Since the new Clipboard API, this is easy in browsers that support it:

javascript: navigator.clipboard.writeText('some text from somewhere');null;

Caveat: Any alerts or prompts in your bookmarklet will cause the document to lose focus, and the clipboard API will become unavailable. In that case you need to move focus back into the document before any subsequent clipboard operations will work:

const oldFocus = document.activeElement; 
/* do popup stuff here */
oldFocus.focus(); 
/* do clipboard stuff here */

Since the new Clipboard API, this is easy in browsers that support it:

javascript: navigator.clipboard.writeText('some text from somewhere');null;

Caveat: Any alerts or prompts in your bookmarklet will cause the document to lose focus, and the clipboard API will become unavailable. In that case you need to move focus back into the document before any subsequent clipboard operations will work:

const oldFocus = document.activeElement; 
//* do popup stuff */
oldFocus.focus(); 
//* do clipboard stuff */

Since the new Clipboard API, this is easy in browsers that support it:

javascript: navigator.clipboard.writeText('some text from somewhere');null;

Caveat: Any alerts or prompts in your bookmarklet will cause the document to lose focus, and the clipboard API will become unavailable. In that case you need to move focus back into the document before any subsequent clipboard operations will work:

const oldFocus = document.activeElement; 
// do popup stuff
oldFocus.focus(); 
// do clipboard stuff

Since the new Clipboard API, this is easy in browsers that support it:

javascript: navigator.clipboard.writeText('some text from somewhere');null;

Caveat: Any alerts or prompts in your bookmarklet will cause the document to lose focus, and the clipboard API will become unavailable. In that case you need to move focus back into the document before any subsequent clipboard operations will work:

const oldFocus = document.activeElement; 
/* do popup stuff */
oldFocus.focus(); 
/* do clipboard stuff */
declare variable
Source Link
Joachim Lous
  • 1.5k
  • 1
  • 17
  • 23

This works for meSince the new Clipboard API, this is easy in chromebrowsers that support it:

javascript: navigator.clipboard.writeText('some text from somewhere');null;

Caveat: Any alerts or prompts in your bookmarklet will cause the document to lose focus, and the clipboard API will become unavailable. In that case you need to move focus back into the document before any subsequent clipboard operations will work:

const oldFocus = document.activeElement; 
// do popup stuff
oldFocus.focus(); 
// do clipboard stuff

This works for me in chrome:

javascript:navigator.clipboard.writeText('some text from somewhere');null;

Caveat: Any alerts or prompts in your bookmarklet will cause the document to lose focus, and the clipboard API will become unavailable. In that case you need to move focus back into the document before any subsequent clipboard operations will work:

oldFocus = document.activeElement; 
// do popup stuff
oldFocus.focus(); 
// do clipboard stuff

Since the new Clipboard API, this is easy in browsers that support it:

javascript: navigator.clipboard.writeText('some text from somewhere');null;

Caveat: Any alerts or prompts in your bookmarklet will cause the document to lose focus, and the clipboard API will become unavailable. In that case you need to move focus back into the document before any subsequent clipboard operations will work:

const oldFocus = document.activeElement; 
// do popup stuff
oldFocus.focus(); 
// do clipboard stuff
clarify that solution is only tested in chrome
Source Link
Joachim Lous
  • 1.5k
  • 1
  • 17
  • 23
Loading
Source Link
Joachim Lous
  • 1.5k
  • 1
  • 17
  • 23
Loading