Search code examples
javascriptwysiwygtampermonkey

Clipboard link pastes into WYSIWYG as code/text instead of link


I have this in a Tampermonkey script:

var journey_link = "<a href='http://www.google.co.uk'>Google</a>";
//...
GM_setClipboard (journey_link);

But when I paste into a WYSIWYG editor, the contents appear as code.

Is it possible to display as the intended hyperlink? Or is this a limitation of WYSIWYG?

Thanks


Solution

  • As wOxxOm said, set GM_setClipboard's info parameter to 'html':

    GM_setClipboard (journey_link, 'html');
    

    This will cause most WYSIWYG editors to treat it as a link, rather than text.

    Reference: The Tampermonkey doc for GM_setClipboard.

    Note that only Tampermonkey and Violentmonkey currently support this. Greasemonkey does not.