Mediawiki Extension add Javascript in Header

前端 未结 2 1580
囚心锁ツ
囚心锁ツ 2020-12-21 11:05

Hi my problem is that i cant load some javascript file @ my special page extension. I tried it with addscript and some other methods but the only thing what happened was th

相关标签:
2条回答
  • 2020-12-21 11:48

    I added it in the skin file, in the function function setupSkinUserCss $out->addHeadItem('maketree.js',"

    <script type='text/javascript' src='/js/mktree.js'></script>");
    
    0 讨论(0)
  • 2020-12-21 11:49

    addScript works in version 1.16 and before. In 1.17 and later you should use addHeadItem:

    $wgHooks['ParserBeforeTidy'][] = 'wgAddJquery';
    
    function wgAddJquery(&$parser, &$text) {
    
      global $addJqueryScripts;
      if ($addJqueryScripts === true) return true;
    
      $parser->mOutput->addHeadItem(
        '<script language="JavaScript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"></script>'
      );
    
      $addJqueryScripts = true;
    
      return true;
    
    }
    
    0 讨论(0)
提交回复
热议问题