Hi !

In Drupal 4.7, I don't understand how to add a javascript file in my page.tpl.php and how to write an onload attribute ?

I hope you can help me ;)
Thanks

Matt

Comments

wickus’s picture

there is a head section in the page.tpl.php where you can but your javascript definitions and a body tag where the onload can be placed to
load your functions
put <script language="JavaScript" src="yourfolder/yourfile.js"></script> in the head section
---
Join the virtual march to stop global warming.
http://www.stopglobalwarming.org/marchers/?142067

Anonymous’s picture

Thanks.
Yes, it's the usual way but in 4.7, the collapsible elements script doesn't work anymore if I use this solution. :-/

Mojah’s picture

We also struggled with this one...here's a hand.

Drupal.js uses addLoadEvent which is a function that replaces window.onload();

In order to make the function work add this code to your page and make sure that drupal.js is also being loaded in every page that you require the event to be called. From my understanding (limited) drupal.js is called in the admin sections, that use collapsable elements. We manually added a reference to drupal.js in our page.tpl.php so that the addLoadEvent is called on every page, but there may be a better solution. As it stands now, drupal.js is called twice in the admin section. It works perfectly.

if (isJsEnabled()) {
  addLoadEvent(your_function);
}
function your_function(){
}

Love, Live, Laugh

Anonymous’s picture

Thanks a lot for your help... I'll try this solution... ;)

robclay’s picture

I am stumped still... (Not hard to do!)

I am trying to get the following javascript (popup Window) to work:

<script language="JavaScript" type="text/JavaScript">

function wimpyPopPlayer(theFile,id,stuff) {
  window.open(theFile,id,stuff);
}

</script>
<p align="center"><B>What's Spinning??</B></p>
<div align="center">
<a href="" onClick="wimpyPopPlayer('http://www.mysite.com/mp3/myWimpy.html','wimpyMP3player','width=485,height=140')"> <img src="http://www.mysite.com/mp3/coverart.jpg" alt="Click to Hear Groove Radio!" width="90" height="90"></a>
</div>


I had this code placed in a block - and it worked fine... I now want to move it to my page.tpl.php.

Thanks for any and all help!