<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://docs.sandbox.joomla.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jimtripp</id>
	<title>Joomla! Documentation - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://docs.sandbox.joomla.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Jimtripp"/>
	<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/Special:Contributions/Jimtripp"/>
	<updated>2026-07-10T12:30:23Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://docs.sandbox.joomla.org/index.php?title=Adding_JavaScript&amp;diff=8897</id>
		<title>Adding JavaScript</title>
		<link rel="alternate" type="text/html" href="https://docs.sandbox.joomla.org/index.php?title=Adding_JavaScript&amp;diff=8897"/>
		<updated>2008-06-29T16:33:41Z</updated>

		<summary type="html">&lt;p&gt;Jimtripp: Initial text on adding a sample javascript file.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{cookiejar}}&lt;br /&gt;
===Adding JavaScript===&lt;br /&gt;
----&lt;br /&gt;
This chunk should describe in detail how to add JavaScript to the head of&lt;br /&gt;
a template using the Joomla! 1.5 API calls. It should be aimed at&lt;br /&gt;
people who have only minimal knowledge of PHP, HTML and JavaScript.&lt;br /&gt;
----&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Add the following code to have the javascript library /media/system/js/sample.js included in your template.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
 $document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
 $document-&amp;gt;addScript( &#039;/media/system/js/sample.js&#039; );&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Explanation===&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Ultimately you are trying to have the resulting HTML page have in the &amp;lt;head&amp;gt; ... &amp;lt;/head&amp;gt; area have a javascript include:&lt;br /&gt;
&lt;br /&gt;
For Example:&lt;br /&gt;
 &amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;/media/system/js/sample.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Ensure that the javascript you want to include is in the directory,  from the above example:&lt;br /&gt;
 /media/system/js/sample.js&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
When you are able to load both your page and see the &amp;lt;script&amp;gt; tag in the &amp;lt;head&amp;gt; area, and be able to load the javascript from the address&lt;br /&gt;
&lt;br /&gt;
Again, using the example: &lt;br /&gt;
   &amp;lt;nowiki&amp;gt;http://www.example.com/media/system/js/sample.js&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Then the script is integrated into your page, and you can proceed to using javascript in your HTML.&lt;br /&gt;
&lt;br /&gt;
Do not directly add the &amp;lt;script&amp;gt; to your template&#039;s index.php.&lt;br /&gt;
&lt;br /&gt;
The code will insert the the &amp;lt;script&amp;gt; line where your index.php has the following line:&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;jdoc:include type=&amp;quot;head&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Add this PHP code to your page, in the head, or next to the javascript code you will use, depending on your preference.&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;?php&lt;br /&gt;
 $document = &amp;amp;JFactory::getDocument();&lt;br /&gt;
 $document-&amp;gt;addScript( &#039;/media/system/js/sample.js&#039; );&lt;br /&gt;
 ?&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &lt;br /&gt;
Reload your template and view the paga, and ensure that the sample.js is included in the &amp;lt;head&amp;gt;&lt;/div&gt;</summary>
		<author><name>Jimtripp</name></author>
	</entry>
</feed>