2011-02-03 101 views
3

我正在編寫一個應用程序來嘗試和修改使用JavaScript的頁面,我無法弄清楚我要運行的JavaScript的放置位置。我正在使用$ K的KRL特定jQuery句柄。

  • 我可以在我的KRL規則集/應用程序中使用JavaScript的所有地方在哪裏?
  • 你有沒有一個例子演示在這些方面使用JavaScript?
+0

哇,這個問題看起來很熟悉! :) – Dustin 2011-02-03 17:06:18

回答

3

有兩種方法可以將JavaScript直接放到KRL規則集的網頁中。通過發射塊或外部資源。我們先討論發射塊。

發出可以出現在規則的動作塊或規則集的全局塊中。您可以使用heredocclownhats排放,但小丑是首選。

下面是一個規則發出的JavaScript的例子:

rule emitter { 
    select when web pageview "exampley.com" 
    { 
     emit <| 
      $K("body").append("Hello from a rule."); 
     |>; 
    } 
} 

下面是一個全球性的塊發出的JavaScript的例子:

global { 
    emit <| 
     $K("body").append("Hello from the global block."); 
    |>; 
} 

放置的JavaScript在KRL頁面上的第二種方法是使用external resource

我會向您推薦的具體鏈接的文檔,但你有一個外部的JavaScript資源在您的規則集的元塊,像這樣:

use javascript resource "url-to-resource" 

比方說,我有以下的位於JavaScript文件在my-personal-website.com/awesome.js內容:

$K("body").append("Hello from an external resource."); 

要使用的規則集:

meta { 
    // normal meta stuff... 
    use javascript resource "my-personal-website.com/awesome.js" 
} 

這裏展示兩種不同的方式來放置JavaScript的網頁上的KRL規則集一個完整的規則集:在exampley.com運行的應用程序後,

ruleset a369x151 { 
    meta { 
     name "fun-with-javascript" 
     description << 
      fun-with-javascript 
     >> 
     author "AKO" 
     logging on 

     use javascript resource "http://dl.dropbox.com/u/4917848/js/example-external-resource.js" 
    } 

    global { 
     emit <| 
      $K("body").append("<br/>Hello from the global block."); 
     |>; 
    } 

    rule emitter { 
     select when web pageview "exampley.com" 
     { 
      emit <| 
       $K("body").append("<br/>Hello from a rule."); 
      |>; 
     } 
    } 
} 

動作射擊: exampley.com rocks!

你可以自己嘗試一下獲取應用程序書籤here

相關問題