需重新寫入其值的函數參數可分為 4 類:
<Function name="functionName " paramPatterns="y,y," [type="URL|EXPRESSION|DHTML|DJS" source="*"]/>
其中
name 是 JavaScript 函數的名稱 (必須的)
paramPatterns 指出需重新寫入的參數 (必須的)
y y 的位置會指出需重新寫入的參數。例如,在此語法中,需要重新寫入第一個參數,但第二個參數則不應重新寫入
type 指出此參數所需的值種類 (可選,預設為 EXPRESSION 類型)
source 網頁源 URI (可選,預設為 *,表示在任何網頁中)
函數會將參數視為字串,而此字串則可視為 URL。
本節分為下列部分:
<Function name="functionName" paramPatterns="y,," type="URL" [source="*"]/>
其中
name 是含有 URL 類型參數的函數名稱 (必須的)
paramPatterns 指出需重新寫入的參數 (必須的)
y y 的位置會指出需重新寫入的參數。例如,在此語法中,需要重新寫入第一個參數,但第二個參數則不應重新寫入
type 是函數的類型 (必須的,此值必須為 URL)
source 是具有此函數呼叫之網頁的 URL (可選,預設為 *,表示在任何 URL 中)
假設此網頁的基準 URL 是:
http://abc.sesta.com/test/rewriter/test1/jscript/test2/page.html
網頁內容
<script language="JavaScript"> <!-- function test(one,two,three){ alert(one + "##" + two + "##" +three); } test("/test.html","../test.html","123"); window.open("/index.html","gen",width=500,height=500); //--> </SCRIPT>
規則
<Function name="URL" name="test" paramPatterns="y,y,"/> <Function name="URL" name="window.open" paramPatterns="y,,,"/>
輸出
<SCRIPT language="JavaScript"> <!-- function test(one,two,three) { alert(one + "##" + two + "##" +three); } test("gateway-URL/http://abc.sesta.com/test.html"," gateway-URL/http://abc.sesta.com/test/rewriter/ test1/jscript/test.html","123");window.open("gateway-URL/ http://abc.sesta.com/index.html","gen",width=500,height=500); //--> </SCRIPT>
描述
第一個規則指出名稱為 test 的函數中前兩個參數需要重新寫入。因此會重新寫入 test 函數的前兩個參數。第二個規則指出 window.open 函數的第一個參數需要重新寫入。window.open 函數中的 URL 會前置含有函數參數的網頁的閘道 URL 及基準 URL。
這些參數採用表示式值,即 URL 中的計算結果。
本節分為下列部分:
<Function name="functionName" paramPatterns="y" [type="EXPRESSION" source="*"]/>
其中
name 為函數名稱 (必須的)
paramPatterns 指出需重新寫入的參數 (必須的)
y y 的位置會指出需重新寫入的函數參數。上列語法中,僅會重新寫入第一個參數
type 指定 EXPRESSION 值 (可選)
source 是呼叫此函數的網頁的 URI
假設此網頁的基準 URL 是:
http://abc.sesta.com/dir1/dir2/page.html
網頁內容
<script language="JavaScript"> <!-- function jstest2(){ return ".html"; } function jstest1(one){ return one; } var dir="/images/test" var test1=jstest1(dir+"/test"+jstest2()); document.write("<a HREF="+test1+">TEST</a>"); alert(test1); //--> </SCRIPT>
規則
<Function type="EXPRESSION" name="jstest1" paramPatterns="y"/> 或者 <Function name="jstest1" paramPatterns="y"/>
輸出
<script language="JavaScript"> <!-- function jstest2(){ return ".html"; } function jstest1(one){ return one; } var dir="/images/test" var test1=jstest1(psSRAPRewriter_convert_expression(dir+"/test"+jstest2())); document.write("<a HREF="+test1+">TEST</a>"); alert(test1); //--> </SCRIPT>
描述
規則將 jstest1 函數的第一個參數視為 EXPRESSION 函數參數,從而指定此參數需要重新寫入。在網頁內容範例中,第一個參數是僅在執行時間中計算其值的表示式。Rewriter 會將 psSRAPRewriter_convert_expression 函數前置於此表示式之前。從而計算此表示式,並且 psSRAPRewriter_convert_expression 函數在執行階段重新寫入輸出。
以上範例中,不需將 test1 變數作為 JavaScript 變數規則的一部分。jstest1 的函數規則負責執行重新寫入。
其值為 HTML 的函數參數
本機 JavaScript 方法,如會以動態的方式產生 HTML 網頁的 document.write(),歸屬於此種類。
本節分為下列部分:
<Function name="functionName" paramPatterns="y" type="DHTML" [source="*"]/>
其中
name 是函數名稱
paramPatterns 指出需重新寫入的參數 (必須的)
y y 的位置會指出需重新寫入的函數參數。上列語法中,僅會重新寫入第一個參數
假設此網頁的基準 URL 是:
http://xyz.siroe.com/test/rewriter/test1/jscript/JSFUNC/page.html
網頁內容
<script> <!-- document.write(\q<a href="/index.html">write</a><BR>\q) document.writeln(\q<a href="index.html">writeln</a><BR>\q) document.write("http://abc.sesta.com/index.html<BR>") document.writeln("http://abc.sesta.com/index.html<BR>") //--> </SCRIPT>
規則
<Function name="DHTML" name="document.write" paramPatterns="y"/> <Function name="DHTML" name="document.writeln" paramPatterns="y"/> <Attribute name="href"/>
輸出
<SCRIPT> <!-- document.write(\q<a href="gateway-URL/ http://xyz.siroe.com/index.html">write</a><BR>\q) document.writeln(\q<a href="gateway-URL/ http://xyz.siroe.com/test/rewriter/test1/ jscript/JSFUNC/index.html">writeln</a><BR>\q) document.write("http://abc.sesta.com/index.html<BR>") document.writeln("http://abc.sesta.com/index.html<BR>") //--> </SCRIPT>
描述
第一個規則指出 document.write 函數中的第一個參數需要重新寫入。第二個規則指出 document.writeln 函數中的第一個參數需要重新寫入。第三個規則是一個簡單 HTML 規則,指出名稱為 href 的所有屬性皆需重新寫入。在範例中,DHTML 參數規則會識別出函數中需重新寫入的參數。然後便套用 HTML 屬性規則,以實際重新寫入識別出的參數。
其值為 JavaScript 的函數參數。
本節分為下列部分:
<Function name="functionName" paramPatterns="y" type="DJS" [source="*"]/>
其中
name 是含有一個 DJS 參數的函數名稱 (必須的)
paramPatterns 指出上列函數中哪一個參數是 DJS (必須的)
y y 的位置會指出需重新寫入的函數參數。上列語法中,僅會重新寫入第一個參數
type 是 DJS (必須的)
source 是網頁的 URI (可選,預設為 *,表示任何 URI)
假設此網頁的基準 URL 是:
http://abc.sesta.com/page.html
網頁內容
<script> menu.addItem(new NavBarMenuItem("All Available Information","JavaScript:top.location=\qhttp://abc.sesta.com\q")); </script>
規則
<Function name="DJS" name="NavBarMenuItem" paramPatterns=",y"/> <Variable name="URL">top.location</Variable>
輸出
<script> menu.addItem(new NavBarMenuItem("All Available Information", "JavaScript:top.location=\qgateway-URL/ http://abc.sesta.com\q")); </script>
描述
第一個規則指出 NavBarMenuItem 函數中的第二個包含 JavaScript 的參數需要重新寫入。在 JavaScript 中,top.location 變數亦需重新寫入。將使用第二個規則來重新寫入此變數。