Example: web_js_run and web_js_reset
web_js_run("Code= alert('Hello world');", LAST);
// 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);
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 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);
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 );
web_js_reset();