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.
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.
Since the JavaScript tags are activated from within the <head /> tag, you cannot use document.write() or similar inline JavaScript statements.
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.
This page contains this code:
<script src="example.js"></script>
To see an example using external JavaScript:
- Create a text file in the same directory as this wiki.
- Paste this into the file:
alert("This is an example alert!");
- Save the file as example.js
- Reload the wiki.
- Open this page from the menu (not in the help pop-up) to run the example.js script and see the alert.
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.
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:
- This one uses the temporary page name as part of its content:
<script>function temporary(arg) {return 'This page was dynamically created using *'+arg+'* as content!';}</script>[[Javascript::temporary('sample')|Click here]]
- This one demonstrates the use of various HTML tags in the content of the page:
<script>function temporary(arg) {return 'This page contains more than one line.<br>This line contains <b>bold</b>, <i>italic</i>, <u>underlined</u>, and <font color="red">colored</font> text.<br><br>And here is a list:<br><ul><li>item1</li><li>item2</li><li>item3</li></ul>';}</script>[[Javascript::temporary('My Page')|Click here]]
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.
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.
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.
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.