4D v17.4WA Evaluate JavaScript | 
            |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
                 
                
  | 
                
			
                    
                         
    4D v17.4
 
WA Evaluate JavaScript 
                                
                                
        
 | 
                ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| WA Evaluate JavaScript ( {* ;} object ; jsCode {; type} ) -> Function result | ||||||||
| Parameter | Type | Description | ||||||
| * | Operator | 
             
         | 
        If specified, object is an object name (string) If omitted, object is a variable | |||||
| object | Form object | 
             
         | 
        Object name (if * is specified) or Variable (if * is omitted) | |||||
| jsCode | String | 
             
         | 
        JavaScript code | |||||
| type | Longint | 
             
         | 
        Type into which to convert result | |||||
| Function result | Date, Object, Pointer, Real, Text, Time | 
             
         | 
        Result of evaluation | |||||
The WA Evaluate JavaScript command executes, in the Web area designated by the * and object parameters, the JavaScript code passed in jsCode and returns the result. This command must be called after the page is loaded (the On End URL Loading form event must have been generated).
By default, the command returns values as strings. You can use the optional type parameter to specify typing for the value returned. To do this, pass one of the following constants, found in the "Field and Variable Types" theme:
| Constant | Type | Value | 
| Is Boolean | Longint | 6 | 
| Is collection | Longint | 42 | 
| Is date | Longint | 4 | 
| Is longint | Longint | 9 | 
| Is object | Longint | 38 | 
| Is real | Longint | 1 | 
| Is text | Longint | 2 | 
| Is time | Longint | 11 | 
This example of JavaScript code causes the previous URL to be displayed:
 $result:=WA Evaluate JavaScript(MyWArea;"history.back()")This example shows a few evaluations with conversion of the values received.
JavaScript functions placed in an HTML file:
<!DOCTYPE html>
<html>
    <head>
        <script>
        function evalLong(){
            return 123;
        }
        function evalText(){
            return "456";
        }
        function evalObject(){
            return {a:1,b:"hello world"};
        }
        function evalDate(){
            return new Date();
        }
    </script>
    </head>
    <body>
        TEST PAGE
    </body>
</html>In the 4D form method, you write:
 If(Form event=On Load)
    WA OPEN URL(*;"Web Area";"C:\\myDatabase\\index.html")
 End ifYou can then evaluate the JavaScript code from 4D:
 $Eval1:=WA Evaluate JavaScript(*;"Web Area";"evalLong()";Is longint)
  //$Eval1 = 123
  //$Eval1 = "123" if type is omitted
 $Eval2:=WA Evaluate JavaScript(*;"Web Area";"evalText()";Is text)
  //$Eval2 = "456"
 $Eval3:=WA Evaluate JavaScript(*;"Web Area";"evalObject()";Is object)
  //$Eval3 = {"a":1,"b":"hello world"}
 $Eval4:=WA Evaluate JavaScript(*;"Web Area";"evalDate()";Is date)
  // $Eval4 = 06/21/13
  // $Eval4 = "2013-06-21T14:45:09.694Z" if type is omitted
	Product:  4D
	Theme:  Web Area
	Number:  
        1029
        
        
        
	
	Created:  4D v11 SQL Release 2
	Modified:  4D v14
	Renamed: 4D v14
	Modified:  4D v16 R4
	
	
	
	4D Language Reference ( 4D v17)
	
	
	
	
	4D Language Reference ( 4D v17.1)
	
	4D Language Reference ( 4D v17.2)
	4D Language Reference ( 4D v17.3)
	4D Language Reference ( 4D v17.4)
Add a comment