JavaScript

Adding JavaScript to your page

To add JavaScript to your page, you must enclose it inside JavaScript tags.

Use this code in a page, replacing YOUR_CODE_HERE with your JavaScript code:
<script type="text/javascript"> YOUR_CODE_HERE </script>

To add JavaScript to your page.

Adding JavaScript to the wiki source

It is possible to add <script/> tags to your wiki source and they will be correctly rendered in the document <head/> tag upon page loading; also external scripts (using the src attribute) will be parsed and activated, always respecting the order of declaration of the <script /> tags.

Info Since the JavaScript tags are activated from within the <head /> tag, you cannot use document.write() or similar inline JavaScript statements.

Using external JavaScript

You can include external JavaScript on a page by placing the script file in the same directory as this wiki and then inserting a reference to it in the body of the page.

Use this code in a page, replacing SCRIPTNAME.JS with the name of your script:
<script src="SCRIPTNAME.JS"></script>

To include an external JavaScript in a page.

Example

This page contains this code:
<script src="example.js"></script>

To see an example using external JavaScript:
  1. Create a text file in the same directory as this wiki.

  2. Paste this into the file:
    alert("This is an example alert!");

  3. Save the file as example.js

  4. Reload the wiki.

  5. Open this page from the menu (not in the help pop-up) to run the example.js script and see the alert.

Using JavaScript to create a temporary page

Using this code, you can get this wiki to create a link to a dynamically created temporary page with custom content (it accepts HTML tags as part of the content) under the JavaScript namespace. The temporary page will be created each time the link is clicked, and it will be uncreated as soon as you navigate to another page or close the wiki.

Use this code in a page, replacing CONTENT with your content, NAME with the page name, and LINK with the text you want the link to have:
<script>function temporary(arg) {return 'CONTENT';}</script>[[Javascript::temporary('NAME')|LINK]]

To create a dynamically created temporary page.

Info Only one of these links may be used per page.

Paste each of these into a new page one by one to see what they do:

Using JavaScript for page redirection

The code below will redirect from the current page to the wiki page you specify a predefined number of seconds after the current page loads.

Info WARNING! Use this code carefully! Back up your wiki before trying it!

Use this code in a page, replacing PAGENAME with the name of the page to redirect to, and 10 with the number of seconds the script should delay:
<script type="text/javascript"> setTimeout("go_to('PAGENAME')",10*1000); </script>

To redirect the current page to the PAGENAME page 10 seconds after the current page loads.

Info Note that this will redirect to the next page even if you're in the editor! The only indication you will have if you're in the editor is that name in the the Page title box will change to the name of the redirected page. If you don't check this before saving, your changes will be saved to the redirected page, overwriting its contents.

It's a good idea to put this code near the top of any page (preferably directly beneath the first header on the page) so that you can find it quickly, and also to make the delay at least 10 seconds so that you have time to open the page in the editor, change the PAGENAME portion of the code to a nonexistent page, and then save the page before the timer runs out.

Then you can reopen the page safely without risk of it redirecting while you're working on it. All that will happen if you give the script a nonexistent page name is that an alert will pop up asking if you'd like to create the nonexistent page. You can click Cancel when that popup comes up and continue working without further interruption.

An even safer method is to open the wiki in a text editor and make changes to the page contents from there.

Using JavaScript to reload the wiki

Use this code in a page:
<input type="button" value="Reload wiki" onClick="window.location.href=window.location.href">

To create a button that reloads the wiki when you click it.