Talk:Adding JavaScript to Wiki Pages

Jump to navigation Jump to search

This howto is easy to understand also without js skill. but I had to change the js code (from MediaWiki:YourScript.js) as it is described here (thanks to Krinkle from "mediawiki-l Mail-List"). I did the import code as recommended with importScript('MediaWiki:YourScript.js') (in MediaWiki:Common.js); and create a Template:HelloWorld and use that within pages but nothing happens. Do I forgot to activate or to allow js in mediawiki settings? In LocalSettings.php I set: $wgUseSiteJs = true; $wgAllowUserJs = true; $wgAllowUserCss = true; Is there any simple way to check js is running in my mediawiki? Ggtuem (talk) 14:16, 4 September 2014 (UTC)

why not support js newbies with a "hello world" howto? Ggtuem (talk) 10:57, 5 September 2014 (UTC)

Example Hello World!!![edit]

Here is a quick step-by-step for Hello World!!!:

Add to the following MediaWiki:Common.js:

(function () {

  var myElement = document.getElementById('mw-hello-world');
  myElement.innerHTML = '<html>Hello World!!!</html>';


Create the page Template:Helloworld with the following:

<div id="mw-hello-world"></div>

Go to a regular page in the wiki and add the following:


You should see Hello World!!! on the page after saving. Nephron (talk) 02:05, 28 October 2016 (UTC)

importScript is now deprecated[edit]

importScript is now depricated
Please replace the code snippet under Separate Script


with the updated version

mw.loader.load( '/w/index.php?title=MediaWiki:Gadget-HotCat.js&action=raw&ctype=text/javascript' );