MyBB Community Forums

Full Version: Adding JavaScript to every page.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I really don't know how to explain this clearly, but I'll do my best.
I have a JavaScript code that will rewrite all the links on the page. I want the JavaScript code to be used on every thread. How do I do this?
Insert it in the header template.
(2010-06-09, 04:12 AM)Iamazn Wrote: [ -> ]I want the JavaScript code to be used on every thread.

If it is only every thread you need the javascript, then add it to the showthread template. Go to Admin CP => Templates & Style => Templates (on the left) => (the theme templates you want to edit) => Showthread Templates => showthread.

Add the <script> tags after {$headerinclude}...
(2010-06-09, 07:28 AM)Tomm M Wrote: [ -> ]
(2010-06-09, 04:12 AM)Iamazn Wrote: [ -> ]I want the JavaScript code to be used on every thread.

If it is only every thread you need the javascript, then add it to the showthread template. Go to Admin CP => Templates & Style => Templates (on the left) => (the theme templates you want to edit) => Showthread Templates => showthread.

Add the <script> tags after {$headerinclude}...
Why won't this JS Code work? It works fine when I use it in a HTML file.
for (var i = 0; i < document.links.length; i++)
{
if (!(document.links[i].href.indexOf("mydomain.com")> -1))
{
document.links[i].href = 'http://www.mydomain.com/redirect.php?' + document.links[i].href;
}

}
You need to add
<script> {Your code here} </script>
O_o (It might work...)
(2010-06-09, 01:54 PM)darkly Wrote: [ -> ]You need to add
<script> {Your code here} </script>
O_o (It might work...)
Thats where I put it, it wont work. D:
Try
<script type="text/javascript"> {code here} </script>
?
You need the type of script to be run. Sometimes adding just <script> does nothing.
Hmm that should of worked i guess.
The code I posted doesnt work, but when I add:
alert('test');
It'll alert "test", but the other code doesn't work.