Where can I use jQuery $ K in the KRL rule set?

I am writing an application to try to change the page using JavaScript, and it’s hard for me to figure out where to put the JavaScript that I want to run. I use a specific jQuery KRL handle in $ K.

  • Where are all the places where I can use JavaScript in my KRL ruleset / applications?
  • Do you have an example demonstrating the use of JavaScript in each of these areas?
+3
source share
1 answer

There are two ways to place javascript directly on a web page inside a KRL rule set. Through an emitting block or external resource. Let them first discuss what happens to the blocks.

. heredoc clownhats, .

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 - .

, 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:

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: exampley.com rocks!

, bookmarklet .

+3

Source: https://habr.com/ru/post/1789635/


All Articles