Moodle load an external javascript file from URL

Moodle load an external javascript file from URL

Crazy Coder -
Vastausten määrä: 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'.
Arviointien keskiarvo:Useful (1)
Vastaus Crazy Coder

Re: Moodle load an external javascript file from URL

Purnendu Dash -
Kuva: 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

Arviointien keskiarvo:Useful (1)
Vastaus Purnendu Dash

Re: Moodle load an external javascript file from URL

Crazy Coder -

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

Arviointien keskiarvo:Useful (1)