News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Inserting Javascript

Started by Poppet, June 25, 2005, 12:59:19 PM

Previous topic - Next topic

Poppet

We've got a neat little javascript which when you hover over a link it changes colour in a sequence.

The problem is we haven't got a clue where to put it to make it work, we've tried adding it to the index-template.php but that just brings up a parse error.

In the instructions it says to add it to the <head> section, but we are unsure which file to put it in so it's global to the whole board  :-[ :-[

<script src="rainbow.js">

/*
Rainbow Links Script- TAKANASHI Mizuki
For full source code, 100's more DHTML scripts, and TOS,
Visit http://www.dynamicdrive.com
*/

</script>


That's the code we want to add, we also need to upload a file called rainbow.js to a directory but again not sure where it goes.

I'd attach the rainbow.js but dont know how.


Chris Cromer

You need to escape strings when placing things into the template.

The index.template.php file is the correct file, and you do need to insert it into the head section like it says. But use this code instead:

<script src="rainbow.js">

/*
Rainbow Links Script- TAKANASHI Mizuki
For full source code, 100\'s more DHTML scripts, and TOS,
Visit http://www.dynamicdrive.com
*/

</script>


That apostraphe was causing the parse error. And the backslash before it will prevent it from happening.
Chris Cromer

"I was here, here I was, was I here, sure I was" - The little voice in my head.

Poppet

Thanks Chris I tried that and we're not getting the parse error anymore, unfortunately the script doesnt work though  :(

I put the rainbow.js in the themes directory because there were other .js files in there so I figured that's where it should go.

Have I put the code in the wrong place? this is where I put it, at the bottom just above the </head> tag.

// Guests don't have theme options!!
if ($context['user']['is_guest'])
echo '
document.cookie = "upshrink=" + (mode ? 1 : 0);';
else
echo '
document.getElementById("upshrinkTemp").src = "', $scripturl, '?action=jsoption;var=collapse_header;val=" + (mode ? 1 : 0) + ";sesc=', $context['session_id'], ';" + (new Date().getTime());';

echo '
document.getElementById("upshrink").src = smf_images_url + (mode ? "/upshrink2.gif" : "/upshrink.gif");

document.getElementById("upshrinkHeader").style.display = mode ? "none" : "";

current_header = mode;
}
// --></script>
<script src="rainbow.js">

/*
Rainbow Links Script- TAKANASHI Mizuki
For full source code, 100\'s more DHTML scripts, and TOS,
Visit http://www.dynamicdrive.com
*/

</script>
</head>
<body>';

Chris Cromer

No that's the right place to put it. As for why it's working... try putting the rainbow.js file in the main directory of your board.
Chris Cromer

"I was here, here I was, was I here, sure I was" - The little voice in my head.

Poppet

Brilliant it's working now Thank you for your help Chris very much appreciated  :D :D

Advertisement: