MediaWiki Special:MyPage/common.js not working

我的梦境 提交于 2019-12-11 18:38:22

问题


MediaWiki Version and LocalSettings.php
MediaWiki 1.22.4
$wgAllowUserJs = true;
$wgUseSiteJs = true;

Browser Version
FireFox 28.0

JavaScript Code

$ gvim common.js

function myFunction() {
  alert("Hello World!");
}

var onClickAttribute = document.createAttribute("onclick");
onClickAttribute.value="myFunction()";

var button = document.createElement("button");
button.setAttributeNode(onClickAttribute);
button.innerHTML = "Say hello";

if (document.URL === 'http://mywiki.com/w/index.php/User:Pjc/common.js') {
  var wikiaArticle = document.getElementById("WikiaArticle");
  wikiaArticle.insertBefore(button, wikiaArticle.firstChild);
}
:wq!

Browse to
http://mywiki.com/w/index.php/Special:MyPage/common.js click "edit this page"
copy/paste common.js into page
click "Save" button
clear the cache in your browser

THE BUTTON DID NOT DISPLAY!

It just displays the code that was entered.


回答1:


Users javascript should be in MediaWiki:Common.js or under User:YourUserName/common.js. Scripts under Special:Mypage does not work. Please refer https://www.mediawiki.org/wiki/Manual:Interface/JavaScript for details



来源:https://stackoverflow.com/questions/23047188/mediawiki-specialmypage-common-js-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!