General developer forum

Using Javascript on a single page

 
This is me.  Deal with it!
Using Javascript on a single page
 

Hi

I've got a course, just one, that I want to be able to serve a JS file to so I don't want to put it in the theme.  How can I attach it?

I've tried adding it in the summary of the topic with <script> but on save it strips it out again.  Any ideas?

Thanks

Kieran



 
Average of ratings: -
Picture of Mark Johnson
Re: Using Javascript on a single page
Core developersParticularly helpful MoodlersPlugin developers

The simplest answer I can think of is to create a simple block plugin where the get_content() method adds the Javascript, but doesn't actually display any content.  You can then add this block to the course you want the Javascript on, but no others.

 
Average of ratings: -
Picture of AL Rachels
Re: Using Javascript on a single page
Core developersParticularly helpful MoodlersPlugin developersTesters

You should also be able to add JS by using a Generico filter template. Plus you then get the added benefit of being able to use many other Generico filters to enhance your site.

 
Average of ratings: -