Follow

Capriza JavaScript Objects

When configuring Overrides, which enable you to modify a control's web-inherited content and behavior to create a mobile-optimized experience, or using JavaScript in Strengthening, Capriza JavaScript Objects and Functions may sometimes be required. This article provides an overview of these objects and functions as well as example use cases.

Object/
Function

Description

Example Use Case

ctx

Similar to the standard JavaScript window.document object. You can use ctx with standard JavaScript functions, such as getElementById, getElementsByName, querySelector, etc. Please note that the standard window function can be used to get the window.document object itself.

Finding/identifying an element on the web page. For example, you can use ctx when using the JavaScript functionality in Expert Identification mode to strengthen a control.


Example HTML Fragment:

<body>

  ....

  <a href="#" class="capriza">My Link</a>

  ...

</body>


Javascript Identification:

ctx.querySelector("a.capriza");

$x

Exposes the ability to execute xpath queries against a given context, which will return an array of nodes that match the provided query. A second parameter can be added to this function to specify the search content (i.e. where to start executing the xpath).

$x("descendant::A[1]", element)[1]


This function will return the first link found inside the element (if you have element as an existing reference object).

Shared

A shared JavaScript object common to all scripts. You can store basic Javascript objects and primitives in this shared space but not  HTML DOM objects (or references to those objects).

This object is useful for passing data between Zapp pages that is usually only included on one page in the source app. For example, imagine an application where upon logging in, the user is taken to a dashboard that includes various pieces of information, including his or her user ID. Page two of the Zapp (and source app) includes a form for the user to fill out. One of the form's fields is user ID, but it is not automatically pulled in by the source application.

To pre-populate the form, you can save the user ID as a shared object (e.g. "shared.userName = element.textContent") You can then use shared.userName in an Override on the form page to automatically fill in that field. Please refer to the Shared Object article for additional examples.

 

Was this article helpful?
1 out of 1 found this helpful
Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.