Clipboard ​
Copy arbitrary text to the user's clipboard with the frontend event client->cs_event-clipboard_copy. The text travels as the first t_arg entry and is passed to the browser's navigator.clipboard.writeText API, which performs the copy entirely in the browser.
abap
CLASS z2ui5_cl_sample_clipboard DEFINITION PUBLIC.
PUBLIC SECTION.
INTERFACES z2ui5_if_app.
DATA mv_text TYPE string.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS z2ui5_cl_sample_clipboard IMPLEMENTATION.
METHOD z2ui5_if_app~main.
CASE abap_true.
WHEN client->check_on_init( ).
mv_text = `Hello from abap2UI5`.
DATA(view) = z2ui5_cl_ui5_view_builder=>factory(
)->ele( n = `View` ns = `mvc`
)->a( n = `xmlns` v = `sap.m`
)->a( n = `xmlns:mvc` v = `sap.ui.core.mvc`
)->ele( `Page`
)->tag( `Input`
)->a( n = `value` v = client->_bind( mv_text )
)->tag( `Button`
)->a( n = `text` v = `copy to clipboard`
)->a( n = `press` v = client->_event( `COPY` ) ).
client->view_display( view->stringify( ) ).
WHEN client->check_on_event( `COPY` ).
client->follow_up_action(
val = client->cs_event-clipboard_copy
t_arg = VALUE #( ( mv_text ) ) ).
client->message_toast_display( `copied` ).
ENDCASE.
ENDMETHOD.
ENDCLASS.
Copy the App State URL ​
To share the current app state instead of a custom string, compose the link with client->app_state_get_href( ) and hand it to the same clipboard_copy action — see App State.
WARNING
The browser's Clipboard API requires HTTPS (or localhost). On plain HTTP the call is silently ignored.
Working Samples ​
Complete apps from the sample catalog
that use what this page describes. Each is a single class — pull the repository with
abapGit and start it with ?app_start=<class>.
| Sample | Class |
|---|---|
| Copy to Clipboard (A) | Z2UI5_CL_SMP_APP_325 |
| Local and Session Storage (A,C) | Z2UI5_CL_SMP_APP_327 |
Edit this page on GitHub ↗
Last updated: