Adding JavaScript in the text box or similar without it reformatting

Adding JavaScript in the text box or similar without it reformatting

by Angi Wren -
Number of replies: 0

Hi There,

I was wondering if anyone could help?

I am looking after the eLearning content for a University and that includes adding in regular course materials. The problem I have is the lesson material sits outside of the main course area, in what we call a library area so the lesson material can be used multiple times if needed from other courses. This means we can't hard code URL's to the pages, so I have been advised to use JavaScript to link back to the main course page. From what I have experienced Moodle does not like JavaScript in the text box and reformats it to one line, removing all the breaks needed in the code to make it work.

Just to give you an idea of what code I am using, this below sits on a course page:

<script type="text/javascript">// <![CDATA[
	localStorage.setItem('return_url', window.location.href);
	// ]]>
</script>
And this below sits at the top of a lesson page:

<script type="text/javascript">// <![CDATA[ 
function go_back(){window.open (localStorage.getItem('return_url'), '_self', false);} 
// ]]></script>
It works beautifully up to a point and then if you need to go back and edit anything on the pages later it breaks and puts it all on one line.

I am not in a position to get this put into a Functions file or anywhere outside of these pages, I have advised this won't happen, so I only have access to the course pages. so I wonder if anyone had any ideas?

Any help would be appreciated as it's starting to cause a little bit of a headache smile

Thanks
Angi

Average of ratings: -