Bookmarlets are tiny javascript programs stored in a url.
(more here, here
, and here
)
They either live
- in your browser link toolbar, or
- in html pages.
To use bookmarklets in jspwiki pages, you first need to add a javascript interWikiRef in jspwiki.properties:
# javascript, for bookmarklets jspwiki.interWikiRef.javascript= javascript:%s
You can now start inserting bookmarklets into your page :
Ex 1 : search in this JSPWiki#
[search here for...|javascript:location.href='http:Search.jsp?query='+ escape(prompt('search for..',''))+'&ok=Find%21']
Ex 2 : Calculator#
[calculator|javascript:expr=prompt('Formula...(eg: 2*3)','');if(expr){with(Math){evl=parseFloat(eval(expr))}; if(isNaN(evl)){alert('Not a number!')}else{void(prompt('Result:',evl))}}else{void(null)}]
(Everything on one line, of course).
List of supported functions
Ex 3 : is the current page url already stored in the JSPWiki?#
Adapt (for your wiki) this url, and store it in a new url, in your browser toolbar.
javascript:location.href='http://localhost:8080/JSPWiki207/Search.jsp?query=' +escape(location.href)+'&ok=Find%21'
Escaping special characters#
Since JSPWiki recognises ']' as the end-of-link notifier, you can escape it in the Javascript code using its URL encoding "%5d".
For example, the following piece of code would display the different umlauts and their corresponding entities:
[javascript:t='';v=new Array('a','A','e','E','i','I','o','O','u','U');s=new Array ('grave','acute','uml','circ');for(i=0;i<10;i++){for(j=0;j<4;j++){w=v[i%5d+s[j%5d;t+='<font size=+1>&'+w+'; is &am'+'p;'+w+';</font><br />'}};with(document){write(t);void(close())}]
Back to Category Tips
Add new attachment
Only authorized users are allowed to upload new attachments.