[dokuwiki] Re: Javascript Dom question in /conf/userscript.js
From: Andreas Gohr <andi@xxxxxxxxxxxxxx>
To: dokuwiki@xxxxxxxxxxxxx
Date: Mon, 12 Jun 2006 19:41:12 +0200
> There it says:
> >> The current page ID is in a hidden field of the edit form which you
> >> could access from your JavaScript. Just pull it from there.
>
> so my userscript.js is:
>
> if(toolbar){
> var xid = document.getElementsByName("id");
> var ns=xid[1].value;
hmm... shouldn't this be xid[0] for the first found element?
> The problem is though that apparently the document is not yet loaded
> when userscript.js gets evaluated. So the xid[] array will always be
> empty.
You need to wait till the document is loaded and then execute you
script. To do so use the addInitEvent call. Something like this should
work (untested):
function my_toolbar_additions() {
if(!toolbar) return;
var xid = document.getElementsByName("id");
var ns=xid[0].value;
var open = "[["+ns+":";
toolbar[toolbar.length] = {"type":"format",
"title":"newpage_below",
"icon":"below.png",
"key":"",
"open":open,
"close":"]]"};
}
addInitEvent(my_toolbar_addition);
Andi