How do I enable external JavaScript in my Moodle page?

In the Moodle, while we use $PAGE->requires->js_init_call()

to activate JS, as defined in our plugin file module.js

, how to enable Javascript is external resources , which we usually include in the <head>

tags as:

<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>

      

+3


source to share


2 answers


Use the following code to include a javascript file in your code:



$PAGE->requires->js() 

E.g

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

      

+3


source


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

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

      



So the file is loaded socket.io.js

within<head> </head>

+4


source







All Articles