Copy to Web Clipboard

The documentation says that “Clipboard” is supported in all project types. However I’m getting an error “Can’t find a type with this name” when trying to use Clipboard in a Web Project. Thanks for any advice!

https://documentation.xojo.com/api/user_interface/clipboard.html#method-descriptions

The docs are incorrect. Clipboard is certainly not available on console or web projects.

2 Likes

I’ve tried tinkering with ExecuteJavaScript and ‘navigator’, but without any success. Has anyone used JavaScript to accomplish this?

// non-successful example
ExecuteJavaScript("navigator.clipboard.writeText('Hello!');")

It’s tricky. For security reasons, browsers won’t allow to access their clipboard API, unless the code trying to access it is executed as a result of direct user interaction, if I recall.

For example, pressing on a button will call the backend and it will receive the ExecuteJavascript code you’re trying to use. As it’s asynchronous, that’s not considered direct interaction :confused:

You can create a custom Web SDK button that executes that code directly, on the client side (I have an example if you want it)

Maybe others have more suggestions. :crossed_fingers:

2 Likes

Thanks Ricardo, I have yet to get into the Web SDK. Perhaps this is a good time to expand my skillset.

1 Like

Thanks, I’ll get someone to look into fixing this.

1 Like

Check this : How To Copy to Clipboard

HI Michel - I found that exact link earlier, and could not get it to work. :frowning:

You are right. It does not work on my Mac with the Try it code.

To be frank, though, I was surprised to find a JavaScript method.

There’s nothing to fix for Console. They don’t have access to those APIs.

Web is… troublesome. Support for clipboard different on just about every browser.

I guess she is talking about the documentation.

Yes, so it would seem. I will find a way to close this ticket with at least some amount of breadcrumbs for future explorers.