<!-- https://abap2ui5.github.io/docs/cookbook/browser_interaction/url_handling -->

# URL Handling

Working with URLs is common — reading parameters from the current URL, opening links in new tabs, or managing browser history.

## Read URL Parameters

Read query parameters from the current URL via the config object:
```abap
DATA(lv_search) = client->get( )-s_config-search.
```

## Open a New Tab
Open a URL in a new browser tab via a frontend event:
```abap
DATA(lv_url) = `https://www.abap2UI5.org`.
client->follow_up_action(
    val   = client->cs_event-open_new_tab
    t_arg = VALUE #( ( lv_url ) ) ).
```

## Browser History

`client->hash_set( )` (UI5's `HashChanger#setHash`) writes a pushed entry into
the browser history from the backend, so a state inside your app becomes
bookmarkable and the Back button steps through the states you pushed:

```abap
client->hash_set( `&my-app-state=detail` ).
```

That is one of three things that can own the URL hash, and which one an app
should use is a decision of its own — see
[Navigation → Hash](/cookbook/event_navigation/navigation/hash), which also
covers framework routing, the twin `hash_replace( )` that writes *without* a
history entry, and `cs_event-hash_back` for stepping back from ABAP.

::: tip Register a listener and the value becomes the whole hash
Used on its own, as above, `hash_set( )` appends its value to the hash. An app
that registers
`cs_event-hash_attach_changed` owns the hash outright, and the same call then
writes `#/detail` the way a UI5 router does, with browser Back/Forward
round-tripping back into the running app. That is the
[app-owned routing](/cookbook/event_navigation/navigation/hash#app-owned-routing)
section.
:::

## All Three in One App

```abap
CLASS z2ui5_cl_sample_url DEFINITION PUBLIC.

  PUBLIC SECTION.
    INTERFACES z2ui5_if_app.

    DATA mv_search TYPE string.

  PROTECTED SECTION.
  PRIVATE SECTION.
ENDCLASS.

CLASS z2ui5_cl_sample_url IMPLEMENTATION.
  METHOD z2ui5_if_app~main.

    IF client->check_on_navigated( ).

      mv_search = client->get( )-s_config-search.

      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`
                  )->a( n = `title` v = `URL Handling`

                  )->tag( `Label`
                      )->a( n = `text` v = `the query string this app was started with:`
                  )->tag( `Text`
                      )->a( n = `text` v = client->_bind( mv_search )
                  )->tag( `Button`
                      )->a( n = `text`  v = `open abap2UI5.org in a new tab`
                      )->a( n = `press` v = client->follow_up_action(
                                               val   = client->cs_event-open_new_tab
                                               t_arg = VALUE #( ( `https://www.abap2UI5.org` ) ) )
                  )->tag( `Button`
                      )->a( n = `text`  v = `push a history entry`
                      )->a( n = `press` v = client->_event( `PUSH` ) ).

      client->view_display( view->stringify( ) ).

    ELSEIF client->check_on_event( `PUSH` ).
      client->hash_set( `&my-app-state=detail` ).
      client->message_toast_display( `pushed - the browser Back button now has a step to take` ).

    ENDIF.

  ENDMETHOD.
ENDCLASS.
```

The *open a new tab* button carries no roundtrip at all — the call sits in the
view attribute, so the browser runs it on the press. The *push* button does,
because the backend decides what to push.

<!-- samples:start (generated by scripts/link-samples.mjs — do not edit) -->

## Working Samples

Complete apps from the [sample catalog](https://github.com/abap2UI5/samples/blob/main/SAMPLES.md)
that use what this page describes. Each is a single class — pull the repository with
[abapGit](https://abapgit.org) and start it with `?app_start=<class>`.

| Sample | Class |
|---|---|
| Open a URL in a New Tab (A) | [`Z2UI5_CL_SMP_APP_073`](https://github.com/abap2UI5/samples/blob/main/src/01/z2ui5_cl_smp_app_073.clas.abap) |
| Open Mail, Phone and SMS Links (A) | [`Z2UI5_CL_SMP_APP_316`](https://github.com/abap2UI5/samples/blob/main/src/01/z2ui5_cl_smp_app_316.clas.abap) |
| Reload the Page (A) | [`Z2UI5_CL_SMP_APP_492`](https://github.com/abap2UI5/samples/blob/main/src/01/z2ui5_cl_smp_app_492.clas.abap) |

<!-- samples:end -->
