Share this page

# Example: web_js_run and web_js_reset

Hello world

    web_js_run("Code= alert('Hello world');", LAST);

Defining and invoking a function

    // Save the value 3 to parameter "Sum"
    web_js_run("Code= myFunc(1, 2);",
    	"ResultParam=Sum",
    	"ActionStep=NO",
    	SOURCES,
    	"Code= var myFunc = function(x,y) { return x+y; }", ENDITEM,
    	LAST);

    // Simple string manipulation
    web_js_run("Code= myFunc('abc', 'def');",
    	// myFunc was defined in the previous step.
    	// No need to redefine, unless web_js_reset() was called.
    	"ResultParam=ConcatStr",
    	LAST);

Running JavaScript from a URL by downloading it and saving it to a parameter

    web_set_max_html_param_len("4000");

    web_reg_save_param("js_url_body",
    	"LB=",
    	"RB=",
    	"Search=body",
    	"RelFrameId=1",
    	LAST);

    web_url("js_url",
    	"URL=http://127.0.0.1:1080/WebTours/myCode.js",
    	"TargetFrame=",
    	"Resource=0",
    	"RecContentType=text/html",
    	"Referer=",
    	"Snapshot=t1.inf",
    	"Mode=HTML",
    	LAST);

    web_js_run("Code=eval(LR.getParam('js_url_body'));",
    		   LAST);

Running code from files in the script folder

    // Running autorun.js
    web_js_run(
    	"File=autorun.js",
    	LAST);

    // 1) Loading code.js
    // 2) Calling function F(a,b), which is defined in code.js
    // 3) Writing the return value of the call to F(a,b) to param1
    web_js_run(
    	"Code=F(a , b)",
    	"ResultParam=param1",
    	SOURCES,
    	"File=code.js", ENDITEM,
    	LAST);

Sending XMLHttpRequest request using script parameters

This code is in the “send_request.js” file in the script folder:

    	var request = new XMLHttpRequest();
    	request .open('POST','validate_request.asp',true);
    	var session = LR.getParam('sessionParam');
    	var custom = LR.getParam('customParam');
    	request.send('my_session=' + session + '&my_custom=' + custom);
    	request.responseText;

Values are saved to parameters 'sessionParam' and 'customParam'.

    web_reg_save_param_ex(
        "ParamName=customParam",
        "LB=:  \"",
        "RB=\",",
        SEARCH_FILTERS,
        "Scope=Body",
        "RequestUrl=*/generate_json_2_parameters.asp*",
        LAST);

    web_reg_save_param_ex(
        "ParamName=sessionParam",
        "LB=:  \"",
        "RB=\",",
        "Ordinal=2",
        SEARCH_FILTERS,
        "Scope=Body",
        "RequestUrl=*/generate_json_2_parameters.asp*",
        LAST);

    web_url("generate_json_2_parameters.asp",
        "URL=http://myServer/cgi-bin/json/generate_json_2_parameters.asp",
        "TargetFrame=",
        "Resource=0",
        "RecContentType=text/html",
        "Referer=http://myServer/cgi-bin/json/json_correlation_2parameters.asp",
        "Snapshot=t2.inf",
        "Mode=HTML",
        LAST);

The request is sent to 'http://www.mydomain.com/cgi-bin/json/validate_request.asp'. The response is saved to parameter "response".

    web_js_run( "File=send_request.js",
    	"Domain=http://www.mydomain.com/cgi-bin/json",
    	"ResultParam=response",
    	LAST );

Resetting the JavaScript engine context

    web_js_reset();

Tips to improve your search results... VuGen Function Reference Version 25.1-25.3 Function Reference 25.1-25.3 All View Local Help Center View Online Help Center Version: