Hi everybody, i´m trying to insert a javascript line from a custom module. I´ve seen the hook_footer module and it does exactly what i need but not in the header section as i need. a link t some code should be a great help. thanks a lot in advance.
Alex Moreno wrote:
Hi everybody,
i´m trying to insert a javascript line from a custom module. I´ve seen the hook_footer module and it does exactly what i need but not in the header section as i need.
a link t some code should be a great help.
thanks a lot in advance.
something like this: drupal_add_js( drupal_get_path('module', $modulename).$javascripturl ); http://api.drupal.org/api/function/drupal_add_js -- Sean Burlington www.practicalweb.co.uk London
i saw peoples adding js in header on hook_menu in not cache section... cya On Jan 22, 2008 10:20 AM, Alex Moreno <al3xmor3no@gmail.com> wrote:
Hi everybody,
i´m trying to insert a javascript line from a custom module. I´ve seen the hook_footer module and it does exactly what i need but not in the header section as i need.
a link t some code should be a great help.
thanks a lot in advance.
-- Pedro Faria de Miranda Pinto http://www.eusouopedro.com http://www.phpavancado.net
You can use hook_init, but you need to check if you are serving a cached page or not. Just check for the existence of some function that will only be there on a full bootstrap. I am assuming you are talking about Drupal 5. In Drupal 6 you don't need to do the check (and, last time I tested, drupal_add_js wasn't working in hook_footer in Drupal 6). cheers, -tao Alex Moreno wrote:
Hi everybody,
i´m trying to insert a javascript line from a custom module. I´ve seen the hook_footer module and it does exactly what i need but not in the header section as i need.
a link t some code should be a great help.
thanks a lot in advance.
Thanks a lot for your answers. I´ve tested this: hook_init("<script></script>"); and the drupal_add_js, but i don´t need to just insert a library but also insert some pieces of code to force the execution when the page is loading and inserting some params from the drupal database. Someting like this: print '<script type=text/javascript>function mainload(){mostrar(' . $latitude . ',' . $longitude . ',"' .$msg.'");}</script>'; On 22/01/2008, Tao Starbow <starbow@citris-uc.org> wrote:
You can use hook_init, but you need to check if you are serving a cached page or not. Just check for the existence of some function that will only be there on a full bootstrap. I am assuming you are talking about Drupal 5. In Drupal 6 you don't need to do the check (and, last time I tested, drupal_add_js wasn't working in hook_footer in Drupal 6).
cheers, -tao
Alex Moreno wrote:
Hi everybody,
i´m trying to insert a javascript line from a custom module. I´ve seen the hook_footer module and it does exactly what i need but not in the header section as i need.
a link t some code should be a great help.
thanks a lot in advance.
-- Alejandro Moreno López Publicidad en Buscadores y Marketing Online http://www.tdo.es
You might try this: drupal_set_html_head("<script src='http://example.com/test.js' type='text/javascript'></script>"); On Jan 23, 2008 3:10 AM, Alex Moreno <al3xmor3no@gmail.com> wrote:
Thanks a lot for your answers. I´ve tested this:
hook_init("<script></script>");
and the drupal_add_js, but i don´t need to just insert a library but also insert some pieces of code to force the execution when the page is loading and inserting some params from the drupal database. Someting like this:
print '<script type=text/javascript>function mainload(){mostrar(' . $latitude . ',' . $longitude . ',"' .$msg.'");}</script>';
On 22/01/2008, Tao Starbow <starbow@citris-uc.org> wrote:
You can use hook_init, but you need to check if you are serving a cached page or not. Just check for the existence of some function that will only be there on a full bootstrap. I am assuming you are talking about Drupal 5. In Drupal 6 you don't need to do the check (and, last time I tested, drupal_add_js wasn't working in hook_footer in Drupal 6).
cheers, -tao
Alex Moreno wrote:
Hi everybody,
i´m trying to insert a javascript line from a custom module. I´ve seen the hook_footer module and it does exactly what i need but not in the header section as i need.
a link t some code should be a great help.
thanks a lot in advance.
-- Alejandro Moreno López Publicidad en Buscadores y Marketing Online http://www.tdo.es
Hmm, I don't think you are grokking the hook system. Anyway, the command you want is drupal_add_js ("function ...", 'inline'); Alex Moreno wrote:
Thanks a lot for your answers. I´ve tested this:
hook_init("<script></script>");
and the drupal_add_js, but i don´t need to just insert a library but also insert some pieces of code to force the execution when the page is loading and inserting some params from the drupal database. Someting like this:
print '<script type=text/javascript>function mainload(){mostrar(' . $latitude . ',' . $longitude . ',"' .$msg.'");}</script>';
On 22/01/2008, Tao Starbow <starbow@citris-uc.org> wrote:
You can use hook_init, but you need to check if you are serving a cached page or not. Just check for the existence of some function that will only be there on a full bootstrap. I am assuming you are talking about Drupal 5. In Drupal 6 you don't need to do the check (and, last time I tested, drupal_add_js wasn't working in hook_footer in Drupal 6).
cheers, -tao
Alex Moreno wrote:
Hi everybody,
i´m trying to insert a javascript line from a custom module. I´ve seen the hook_footer module and it does exactly what i need but not in the header section as i need.
a link t some code should be a great help.
thanks a lot in advance.
participants (5)
-
Alex Moreno -
Pedro Faria de Miranda Pinto -
Sean Burlington -
Tao Starbow -
Xiaodan "Daniel" Zhou