Moodle load an external javascript file from URL

Moodle load an external javascript file from URL

by Crazy Coder -
Number of replies: 5
I am using Moodle 3.1+. I want to load javascript from an external URL into Moodle. I have tried adding it through config file of theme using

$THEME->javascripts_footer = array('pusher.min');
But is not working. I want to integrate Pusher into Moodle and for that, I have to load the script from URL 'https://js.pusher.com/3.2/pusher.min.js'.
Average of ratings: Useful (1)
In reply to Crazy Coder

Re: Moodle load an external javascript file from URL

by Purnendu Dash -
Picture of Plugin developers

You can try the following method. Create a folder named javascript in your theme. Download and copy the pusher.min.js file in it. Now write $THEME->javascripts_footer = array( 'pusher.min' ); in the config file if you want to include the script into the footer [recommended] else use  $THEME->javascripts = array( 'pusher.min' ); If you want to load it into the header.


If you want to include jQuery within the page header you will need to specify true as the second argument.
$PAGE->requires->js('path/to/plugin/javascript/jquery-1.4.2.min.js', true);


Hope this helps.

Regards,

Purnendu

Average of ratings: Useful (1)
In reply to Purnendu Dash

Re: Moodle load an external javascript file from URL

by Crazy Coder -

I included the javascript file in the layout file of moodle.

Average of ratings: Useful (1)