Skip to main content
Question
Wes Bullock
Learning Experience Manager
Asked a question 5 months ago

Does anyone know if there is a way to add Javascript (ex: to show an interactive help widget--we are using Freshdesk) but restrict it to certain courses? I previously added the script to the "Additional HTML" site admin area, but I need to "hide" the widget from certain courses. I found a way to add script to run a URL check, but that only removes the widget from the home page of the course, not all the subpages and activities (which don't even have course-specific URLs anyway). Thank you for any insights!

Where am I?

In The eLearning Community powered by Open LMS you can ask and answer questions and share your experience with others!

Greg Bird
Moodle specialist. Problem solver. Trouble maker. Lane changer.

Could an alternative approach be to deliver the JS via a custom HTML block, rather than Additional HTML?

This way you can be more targetted, and deploy the block within certain courses, or across certain categories, rather than sitewide.

The other approach (although it would require much more maintenance) is to create a blacklist of course ID's, and use JS conditionals to break out of the code if they are in the blacklist.

Are you using Snap?  If so, it helps you greatly here.   It adds the current course ID as a class to the body tag, and this class is available in every page/tool within the course, eg: this is in a book

<body id="page-mod-book-view" class=".... course-2644 ....">

You could extend your current JS to get this body class value, compare it to the blacklist and then either execute the rest of the code, or break out.