O'Reilly logo

Moodle JavaScript Cookbook by Alastair Hole

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Loading a JavaScript file in <head>

In the previous recipe we learned the standard method of including a JavaScript file at the end of the document's<body> tag.

In this recipe, we will look at how to ensure our JavaScript file is included within the<head> tag. There are numerous reasons why you would require your file be included within the<head>, for example if you need to use document.write to manually write<head> content.

Note

If you are in any doubt, use the technique in the previous recipe. If you need to use the technique in this recipe, the chances are you will know exactly why.

Getting ready

Once again, open the Moodle PHP file where we will add our .js file. We will use the simple example from the previous recipe as a basis, with the necessary ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required