Home Cooker Classes Others Rice CookerGX
Classes  >  document  >  InvokeJS(string, anyClass jsArgument, ...)
document class : InvokeJS(string, anyClass jsArgument, ...) method

Description

Executes a javascript function that was loaded for the current document.

Syntax

browserInstance.InvokeJS(string jsFuncName, anyClass jsArgument, ...)

Arguments

ClassNameDescription
stringjsFuncNameFunction name of a javascript.
anyClassjsArgumentArgument for passing to javascript function. Please note that any number of arguments are able to pass.

Return value

ClassDescription
proxyReturn value from a javascript function.

Sample code

document d = new document();

int argument1 = 1;

int argument2 = 2;

proxy returnValue = d.InvokeJS("javascript function name", argument1, argument2);

Notes

It's a wrapper of the System.Windows.Forms.HtmlDocument.InvokeScript(String,Object[]).


About javascript function name.


If the following JavaScript function is already read in the document.


function testJS() {alert('hello world!');}


In order to invoke the above javascript, write in the following manner.


// d is an instance of the document class.

d.InvokeJS("testJS");// 'hello world!' is displayed.


Please note that a parenthesis part do not include in the javascript function name.


About arguments for javascript function.


In the above example, only the javascript function name is passed to the InvokeJS method since the testJS function has no argument.

The following is an example of how to call a javascript function with arguments.

If the following JavaScript function is already read in the document.


function testJS2(stringArg1, stringArg2) { alert( stringArg1 + stringArg2 ); }


It writes as follows to call testJS2.


// d is an instance of the document class.

d.InvokeJS("testJS2", "hello ", "world!");// 'hello world!' is displayed.


You can pass as many arguments as you want for the javascript function as the second and subsequent arguments of the InvokeJS method. In other words, the InvokeJS method is a variable argument method.

The classes that can be passed to the javascript function are int, long, real, bool, string, and element class. Other class can not be passed.


About return value from javascript.


The return value from the javascript is converted to an appropriate instance of the Rice. And, it is stored to an instance of the proxy class and is returned.


・If can be evaluated as an integer in int type range, the return value will be stored as an int.

・If can be evaluated as an integer beyond the int type range, the return value will be stored as a real type.

・If can be evaluated as a real number, the return value will be stored as a real type.

・If can be evaluated as a string, the return value will be stored as a string type.

・If can be evaluated as a boolean value, the return value will be stored as a bool type.

・If the return value can be evaluated as something else or does not exist, a proxy type that have not been initialized will be returned.

Links for reference

Copyright © Rice All rights reserved.