How to include external JavaScript on my Moodle page?

ⅰ亾dé卋堺 提交于 2019-12-07 05:13:27

问题


In Moodle, while we use $PAGE->requires->js_init_call() to include a JS function defined in our plugin's module.js file, how can I include external Javascript resources, which we normally include in the <head> tags like:

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>mypage</title>

<script type="text/javascript" src="http://yui.yahooapis.com/2.5.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>

<script type="text/javascript" src="http://yui.yahooapis.com/2.5.0/build/element/element-beta-min.js"></script>

<script type="text/javascript" src="http://yui.yahooapis.com/2.5.0/build/connection/connection-min.js"></script>

<script type="text/javascript" src="http://yui.yahooapis.com/2.5.0/build/tabview/tabview-min.js"></script>
</head>

回答1:


Use following code to include javascript file in your code:

$PAGE->requires->js() 

E.g

$PAGE->requires->js( new moodle_url($CFG->wwwroot . '/local/my_localplugin/myjavascript.js'));



回答2:


You can use the following code to include a javascript file in your code inside the :

$PAGE->requires->js('/mod/namemodule/socket.io.js',true);

In this way, the file is loaded socket.io.js within the <head> </head>



来源:https://stackoverflow.com/questions/25219176/how-to-include-external-javascript-on-my-moodle-page

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