Skip to content

JavaScript click actions ​

To run code instead of navigating, put js: before the code in the menu item's URL field:

text
js:window.openAppSearch()

Use lowercase js: with no space before the prefix. Click outside the field to save it: after a successful request, the preview reloads automatically with the new handler.

Website function ​

The code runs on the currently open website page. Define the function on your website or under “Advanced settings” → “Additional JS”:

javascript
window.openAppSearch = function () {
    document.querySelector('[data-action="open-search"]')?.click();
};

Replace the search button selector with the one used by your website. The function must be available on every page where users can click the item. If the element is not found, this example does nothing.

You can enter a short action directly in the URL field:

text
js:document.querySelector('[data-action="open-search"]')?.click()

Do not add <script> tags. Defining a function without calling it does not perform the action. Do not include secret keys: app users can access the JavaScript.

Header button ​

In the Ninja editor, set the call in a right button's click field:

json
{
  "CONFIG_VERSION": 1,
  "params": {
    "HEADER_ACTIONS": {
      "right": [
        { "icon": "Search", "click": "js:window.openAppSearch()" }
      ]
    }
  }
}

The current preview supports JavaScript only for right header buttons. Use regular links for left buttons.

Set bottom menu actions in the standard form's URL field: NATIVE_NAV_BAR changes only appearance, and JavaScript from NATIVE_NAV_BAR_ELEMENTS in the JSON is not connected in the current preview.

If the action does not run ​

Temporarily enter js:alert('Test'), click outside the field, and wait for the preview to refresh. If the message appears, check your function name, element selector, and browser console errors. Also test the action after navigating to another website page.

SiteCargo documentation