xoops forums

Shiva

Quite a regular
Posted on: 2009/9/23 19:37
Shiva
Shiva (Show more)
Quite a regular
Posts: 280
Since: 2006/7/9 1
#1

Adding javascript to a block

Can someone please explain the best way to add javascript to a block?

Thanks in advance :)

ghia

Community Support Member
Posted on: 2009/9/23 20:11
ghia
ghia (Show more)
Community Support Member
Posts: 4954
Since: 2008/7/3 1
#2

Re: Adding javascript to a block

If you have one block you can put it between the HTML code.
For use in several blocs put the functions in a js file that is added to the header in theme.html

Shiva

Quite a regular
Posted on: 2009/9/23 21:08
Shiva
Shiva (Show more)
Quite a regular
Posts: 280
Since: 2006/7/9 1
#3

Re: Adding javascript to a block

Ok, I thought it might have been possible to reference a file in a block_show function.
So do you mean that I just put it in the template file ?

Thank you.

Quest

Friend of XOOPS
Posted on: 2009/9/23 22:57
Quest
Quest (Show more)
Friend of XOOPS
Posts: 1034
Since: 2005/11/19
#4

Re: Adding javascript to a block

It all depends on what you really are trying to do. If you are trying to alter an existing block template then you will need to use template override functionality. Or you could be needing to create your own custom block. In that case create your custom block and add your javascript. All depends on what you are trying to do...

Hope this helps,
Quest

ghia

Community Support Member
Posted on: 2009/9/23 23:56
ghia
ghia (Show more)
Community Support Member
Posts: 4954
Since: 2008/7/3 1
#5

Re: Adding javascript to a block

If there is only one block that has to include it, then you can use:
<script type="text/javascript" src="abc.js"></script>
else put it in the head section of your theme.html

optikool

Not too shy to talk
Posted on: 2009/9/30 1:22
optikool
optikool (Show more)
Not too shy to talk
Posts: 154
Since: 2007/3/26
#6

Re: Adding javascript to a block

Quote:

Ok, I thought it might have been possible to reference a file in a block_show function.
So do you mean that I just put it in the template file ?


No you wouldn't put your js code in the show_block function. Find the module that the block belongs, then look for it's template file under templates/blocks and add the code there. If you don't want to go through all that then add it to the header part of your theme.html file.