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:

<script>
function MyFunctionForExecJS1()
{
    alert("MyFunctionForExecJS1");
};

window.MyFunctionForExecJS2 = function()
{
    alert("MyFunctionForExecJS2");
};
</script>


This will not work, it is a private function:

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

But this will work:

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

Article Info
  • Last Updated: 4/1/2015
  • Article ID: KB64
  • Views: 1963