Wikipedia:User scripts/Guide: Difference between revisions

Content deleted Content added
Debugging: Adding more explanation and an example of another way to load a test css file.
Structure: Changed to show the new cleaner "addOnloadHook( function() {" approach we use nowadays.
Line 17:
 
== Structure ==
 
When your <tt>/monobook.js</tt> is executed most [[HTML]] page elements do not exist yet. So most user scripts look like this:
 
<source lang="javascript">
//partPart 1
addOnloadHook(func_start function(); { //meansMeans «execute func_start"function()" later».
 
//partPart 2 — executed when the page ishas loaded
 
//quiteQuite often it simply adds a javascriptJavaScript link
<a onclick="func_action()" href="#">
 
} );
//part 2 — executed when the page is loaded
function func_start (){
 
//andAnd then there is …
//quite often it simply adds a javascript link
<a onclick="func_action()" href="#">
}
//and then there is …
 
//partPart 3 — executed when the user clicks on this link
function func_action (){
}