Yo.
I have a small javascript I want to use in a module I'm building. Although, that script can't run until the page has finished loading or it will generate a script error.
So, my question:
Is it possible to manipulate the tag from my module and insert a onload event handler?
Cheers.
Forum Activity
- Delete user not working on Mar 18
- login hook on Mar 18
- 2 sites 1 database on Mar 18
- Output on Mar 18
- how to change the format of shorturls on Mar 17
- Upgrade Old Postnuke Site on Mar 17
- iPhone-Theme - please test on Mar 17
Zikula Blog
- How to Become a HipHop Fan on Feb 03
- HTML5 on Feb 02
- Support Free Software on Jan 22
- Module Files available on Dec 13
- Why I love Zikula (Reason #768) on Nov 11
- Theme Creator? on Nov 08
- Time to Embrace PHP 5 on Nov 08
Login
inserting a body onload event handler from a module?
-
- Rank: Professional
- Registered: 08.04.02
- last visit: 21.10.09
- Posts: 614
-
**unknown user**
- Rank: Freshman
- Registered: 16.03.02
- last visit: 10.08.04
- Posts: 45
Yes.. thats true...
But is that really a nice way to solve my problem?
If someone else wants to use my module they have to change the theme aswell... nah.. don't think so.
as I see it I have three options here
1. There is some way for me to manipulate the body tag from a module, learn how to do it and smile :)
2. Find out if there is some way to code JavaScript to just wait until the page has finished loading until it starts, learn how to do that and smile. :)
3. Drop the script and use something else. and smile. :) -
**unknown user**
- Rank: Professional
- Registered: 16.03.02
- last visit: 21.10.09
- Posts: 676
Use the $additional_header array which is included in the Header.php before the themeheader() function is called:
Code
$additional_header = array("<script language='JavaScript'>
function functionname() {
etc...
} // end function
onload = function() { functionname(); }
</script>\n");
You might have to inform the user in the ReadMe that if they use a BODY onload event to add your function too:
Code
<BODY onload="function1(); functionname()">
Additionally, you may try to call it in the Body near the bottom of your output:
however your function will be called as soon as the code is read into the browser, even if the page isn't completely loaded, hence it has to appear at the bottom. You could try wrapping it in a timeout:Code
<script language="JavaScript1.2"> functionname(); </script>
window.setTimeout('functionname(this)',1000);
Just some suggestions. -
**unknown user**
- Rank: Freshman
- Registered: 16.03.02
- last visit: 10.08.04
- Posts: 45
Just to clarify things...
the code :
Code
shouldn't that be :
Code
$additional_header[] = "<script language='JavaS........";
otherwise I would risk removing other additional headers made by other modules/blocks? -
**unknown user**
- Rank: Professional
- Registered: 16.03.02
- last visit: 21.10.09
- Posts: 676
-
- Rank: Developer
- Registered: 02.01.03
- last visit: 21.10.09
- Posts: 800
Xanthia has a modulejavascript plugin for this to load the javascript depending on the recent module
An onLoad eventhandler is also supported.
Frank
--
"He is not dangerous, he just wants to play...." -
- Rank: Helper
- Registered: 24.02.03
- last visit: 12.11.09
- Posts: 226
The Xanthia function you are referring to doesn't work when called from a Module...
AND it requires your theme to include special tags...
That option is STRICTLY a workaround for a Theme Developer... NOT a Module developer...
--
That was a hell of a thing...
-------------------------------------
Galaxy Quest
- Moderated by :
- Support
