36.16 Escape Function
This function escapes text to be used in JavaScript. This function uses APEX_ESCAPE.JS_LITERAL
to escape characters and provide a reference to that other API.
Note:
This function prevents HTML tags from breaking the JavaScript object attribute assignment and also escapes the HTML tags '<' and '>'. It does not escape other HTML tags, therefore to be sure to prevent XSS (cross site scripting) attacks, you must also call SYS.HTF.ESCAPE_SC
to prevent embedded JavaScript code from being executed when you inject the string into the HTML page.
Syntax
APEX_JAVASCRIPT.ESCAPE (
p_text IN VARCHAR2 )
RETURN VARCHAR2;
Parameters
Parameter | Description |
---|---|
p_text
|
Text to be escaped. |
Example
Adds some JavaScript code to the onload buffer. The value of p_item.attribute_01
is first escaped with htf.escape_sc
to prevent XSS attacks and then escaped with apex_javascript.escape
to prevent special characters like a quotation mark from breaking the JavaScript code.
apex_javascript.add_onload_code (
'var lTest = "'||apex_javascript.escape(sys.htf.escape_sc(p_item.attribute_01))||'";'||chr(10)||
'showMessage(lTest);' );
Parent topic: APEX_JAVASCRIPT