# WebPages HMI $ Functions

The HMI $ functions provide flexibility and additional functionality compared to strictly using a tag and binding associations, and are designed to interact with a job while online, via a Button element's OnClicked script point, for example.

The WebPages HMI $ functions are "static" HMI functions, and are used to programmatically interact with the entire WebPages infrastructure, versus being associated with a single element or WebPage.

Most of these functions are not asynchronous (that is, they are evaluated in the web browser, not on the vision system), however, the functions associated with the WebPage (such as GetPageTitle, GetPageWidth, etc.) should be treated as though they are asynchronous to handle their return values.

Several functions return a Promise object because JavaScript is asynchronous, and callbacks (that is, Promises) must be used to use the returned value.

    $HMI.CloseDialogPage() : Void
Returns | Void
Arguments | N/A
Description | Closes the active dialog page.

    $HMI.GetControlProperty(controlname,propertyname : String) : Any
Returns | Any
Arguments | controlname: String, specifying the name of the control element. propertyname: String, specifying the name of the property.
Description | Fetches the specified property of the specified control element. Note: Cognex recommends only using this function when an element does not have a published property tag. For a complete list of the published element property tags, see the WebPages Element Property Tags topic. Use this function to access an element property that is not published as a tag. All element properties (for User Inputs, Graphics and Vision Controls and Displays) can be accessed via the $HMI.SetControlProperty() and $HMI.GetControlProperty() functions. The properties of the elements are the same as those exposed in the Web Page Editor, minus the white space between the names (so instead of Border Color, it is BorderColor, for example).

    $HMI.Login(username,password : String) : Void
Returns | Void
Arguments | username: String, specifying the name of the user used for login. password: String, specifying the password of the user used for login.
Description | Logs in to the HMI webpage with the specified username and password.

    $HMI.Logout() : Void
Returns | Void
Arguments | N/A
Description | Logs out of the HMI webpage.

    $HMI.SetControlProperty(controlName,propertyName : String, newValue : Integer, double, Boolean, String) : Boolean
Returns | Boolean
Arguments | controlName: String, specifying the name of the control element. propertyName: String, specifying the name of the property to set. newValue: Integer, double, boolean or string, specifying the new value of the property to set.
Description | Sets the property (specified with the propertyName argument) of the control element (specified with the controlName argument) to a new value (provided with the newValue argument). Note: Cognex recommends only using this function when an element does not have a published property tag. For a complete list of the published element property tags, see the WebPages Element Property Tags topic. Use this function to access an element property that is not published as a tag. All element properties (for User Inputs, Graphics and Vision Controls and Displays) can be accessed via the $HMI.SetControlProperty() and $HMI.GetControlProperty() functions. The properties of the elements are the same as those exposed in the Web Page Editor, minus the white space between the names (so instead of Border Color, it is BorderColor, for example). The function will return true if the property setting is successful, otherwise it will return false.

    $HMI.SetFocusOn(controlName : String) : Void
Returns | Void
Arguments | controlName: String, specifying the name of the control element to focus.
Description | Sets the focus on the control element specified with the controlName argument. Note: This function should be used with a specific control element; the specified element will have focus when the function is called.

    $HMI.ShowError(message,title : String) : Promise
Returns | Promise
Arguments | message: String, specifying the text of the error to show. title: String, specifying the title of the error to show.
Description | Shows the error specified with the message and title arguments.

    $HMI.ShowInformation(message,title : String) : Promise
Returns | Promise
Arguments | message: String, specifying the text of the message to show. title: String, specifying the title of the message to show.
Description | Shows the information message specified with the message and title arguments.

    $HMI.ShowLogin() : Boolean
Returns | Boolean
Arguments | N/A
Description | Shows the login process.

    $HMI.ShowMessage(message : String): Promise
Returns | Promise
Arguments | message: String, specifying the message to show.
Description | Shows the message specified with the message argument.

    $HMI.ShowPage(pageName : String): Void
Returns | Void
Arguments | pageName: String, specifying the name of the web page to show.
Description | Shows the page specified with the pageName argument.

    $HMI.ShowQuestion(message,title : String): Promise
Returns | Promise
Arguments | message: String, specifying the text of the question to show. title: String, specifying the title of the question to show.
Description | Shows the question specified with the message and title arguments.