Knowledge Base Article

Home Page > Knowledge Base > Rapise

Home Page > Knowledge Base > Rapise > Rapise Web

Article Using Navigator.ExecJS to call Javascript functions

by Adam S on Wednesday, April 1, 2015

Sometimes you need to call JavaScript code directly from Rapise rather than firing a DOM event (e.g. clicking on an element) and having that element fire a client-side event handler. This article explains some of the pitfalls and techniques for doing this when you have global functions rather than functions that are part of the core browser model.
On a webpage lets say we have a function addOnClick(num).  We want to execute that function directly in the Rapise script. In the developer console of the web browser we can type in addOnClick(1063) and it will perform the action that we want.  The question is how to execute this function directly in the Rapise script?
The Html is:
<span id="Add" class="Link" onclick="addOnClick(1063)">Add</span>
Unlike simply calling a DOM command such as alert('xxx'); calling this function requires that we actually have this function part of the browser DOM. This is because the Rapise ExecJS function is able to 'see' only DOM model and default methods of global objects (window, document, navigator).

As far as 'alert' is method of 'window' it works. But 'addOnClick' is a regular function defined in the page and it does not work because it is in different namespace.

This explains the difference between two examples below:

function MyFunctionForExecJS1()

window.MyFunctionForExecJS2 = function()

This will not work, it is a private function:

//Open up the IE browser window
Navigator.Find('/html', '',null, {executable:"iexplore.exe"});

But this will work:

//Open up the IE browser window
Navigator.Find('/html', '',null, {executable:"iexplore.exe"});

Article Info
Last Updated: 4/1/2015
Article ID: KB64
# Views: 1620
Powered by KronoDesk v1.1.0.15 | © Copyright Inflectra Corporation 2011-2017 | Licensed to Inflectra Corporation.