REBOL Scripts Embedded Within Web Pages

Author: Carl Sassenrath
Return to REBOL Cookbook


1. Three Methods
2. Script As-Is
3. Script As Web Page Content
4. Hiding Scripts Inside Web Pages

It is really easy to put a REBOL script into a web page, allowing you to run the script directly from the web.

Note that we're not talking here about using REBOL to generate web pages, although that is quite easy too. We mean simply putting a REBOL script on a web site that lets you run the script locally on your computer.

1. Three Methods

There are three basic ways you can do it:

  1. put the script as-is on your web server.

  2. put the script within the content of a real web page.

  3. hide the script within a section of the web page.

(There are probably a few other methods too, but these ones are easy to use.)

2. Script As-Is

The first method just means uploading your script as is to a web site. Here is an example:

    print read http://www.rebol.com/speed.r

You can run this script with:

    do http://www.rebol.com/speed.r

3. Script As Web Page Content

The second method is to put your script inside the HTML for the web page. This may be necessary on some types of web servers that do not like non-HTML types of content.

To post a script this way, you need to know that REBOL has the ability to search for scripts within the text of any kind of file. The secret is, you need to use an extra brackets to tell REBOL the start and end of the script. Here is an example:


    [REBOL [Title: "Example Script"]
        print "This is an example script inside a web page"


Now, you can run the script just as you did above. The code below will actually find the above script on this very page and run it:

    do http://www.rebol.net/cookbook/recipes/0062.html

4. Hiding Scripts Inside Web Pages

The third method is to put your script within an HTML comment or SCRIPT section of the web page. This approach let's the page be normal HTML web content, unless it is run by REBOL.

    <script language=REBOL>
    [REBOL [Title: "Example Script"]
        print "You just ran the hidden REBOL script!"

We put this script at http://www.rebol.net/hidden-script.html. Click on the link to see the page. Now, run this line:

    do http://www.rebol.net/hidden-script.html

2006 REBOL Technologies REBOL.com REBOL.net