This not working has nothing to do with the MediaWiki software. It looks like you have a
thing or to learn about javascript and programming in general. Here's a few tips. Your
script has various issues that contradict how javascript works.
If you'd run this on a regular web page without MediaWiki, Common.js, importScript,
Templates,etc. it will also not work.
1) Can't have multi line string literals in javascript.
If you look at the browser console[1], you'll probably see a SyntaxError due to an
illegal token in the script. To have multiple lines you need a \n character or escape the
literal line break with a slash.
var foo = 'line 1\nline 2';
var bar = 'line A\
line B';
2) Quotes need escaping.
In your snippet the single quote before the "<b>"-tag stops the inner html
string and then runs the < character as part of javascript syntax which doesn't
work.
3) Unknown variable 'newPageElement'.
I think you meant helloWorld. This also generated an error that you could detect yourself
via the console [1].
4) JavaScript inside script tags is not evaluated in dynamically parsed HTML.
To execute javascript in javascript, write is as regular javascript. Not as javascript in
a script tag in html in javascript.
The innerHTML feature can parse and create elements, and it will also create a script
element. But it will not execute the actual code because it has no runtime context. e.g.
document.write doesn't work because the document has already been parsed.
5) To create and render new elements, use the DOM interface.
document.createElement [2]
Node.appendChild [3]
For example:
var helloWorldElement = document.getElementById('helloWorldID');
var msgElement = document.createElement('b');
var msgText = document.createTextNode('Hello world');
msgElement.appendChild(msgText);
helloWorldElement.appendChild(msgElement);
See also
http://jsfiddle.net/7f9uko44/
Again, this is not related to MediaWiki. This is how web browsers, javascript and HTML
work in general.
-- Krinkle
[1]
https://developer.chrome.com/devtools/index
https://developer.chrome.com/devtools/docs/console
[2]
https://developer.mozilla.org/en-US/docs/Web/API/document.createElement
[3]
https://developer.mozilla.org/en-US/docs/Web/API/Node.appendChild
On 3 Sep 2014, at 14:46, Myname To <mailusenet(a)yahoo.de> wrote:
MediaWiki:YourScript.js nothing else than:
var helloWorld = document.getElementById('helloWorldID');
newPageElement.innerHTML = '<script type="text/javascript">
document.write('<b>Hello World</b>');
</script>';
also in MediaWiki:Common.js I have just one single code:
importScript('MediaWiki:YourScript.js');
and for the Template:helloWorld I did only that:
<div id="helloWorldID"></div>
and in MediaWiki:YourScript it stand one word:
{{helloWorld}}
... nothing happens (also after refresh, shift f5 etc.)