MyBB Community Forums

Full Version: How To Add Javascript?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I'm not referring to inserting javascript with the <script type="text/javascript"></script> but the actual Javascript code library thingy, so I can run Javascript on my page.

What do I include between the <head></head> tags, to add Javascript?
unable to understand the requirement. basic java script runs anywhere in the templates.
specific functions run on the templates if their base code is available through the head tags.
Let me clarify. I wanted to know how to add Javascript src="". To basically add Javascript support.

Because I added some Javascript code that works on JSFiddle.net but when I copied and pasted the exact same code into MyBB, the Javascript doesn't work.
^ actual javascript can be also added in the headerinclude template with <script type="text/javascript"> and </script>

can we have the link to the code at JSfiddle to check
(2014-12-02, 11:04 AM).m. Wrote: [ -> ]^ actual javascript can be also added in the headerinclude template with <script type="text/javascript"> and </script>

can we have the link to the code at JSfiddle to check

I tried that, it doesn't work.

http://jsfiddle.net/blazeeboy/fNPvf/
^ you can add the function code in headerinclude template like below
<script type="text/javascript">
 <!--
put your function here
 //-->
</script>
and the html code anywhere you need in templates (eg. header template)
I suggest using http://www.w3schools.com/js/js_whereto.asp to have knowledge about JS and also live test using their example thingy before implemented to your site. Not every JS you input to the example will work, but at least is a go.

- Hope that helps!
My bad. I realized when I tried adding other Javascript code, that it wasn't just Javascript. It was JQuery.

Does anyone know how to add JQuery support?
^ well, for jQuery based functions
MyBB 1.8.x already includes jQuery library and the required script can be added as suggested earlier.

for MyBB 1.6.x , if the theme / plugins do not use jQuery then it needs to be added in headerinclude template.
many like using latest minified Jquery script (jquery.min.js) but I prefer using version 1.7.2 or version 1.9.1

suggested code to include minified jQuery in headerinclude template (from MyAlerts plugin)
<script type="text/javascript">
if (typeof jQuery == 'undefined') {
    document.write(unescape("%3Cscript src='http://code.jquery.com/jquery-1.7.2.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script>
Hi, yes I need 1.7.2 as that is what everyone seems to use, and that is what a JQuery example I found uses too.