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.
Watch
GitHub Core
Show your support for Zikula! Sign up at Github account and watch the Core project!
GitHub Modules
- mesteele101 created topic »ERR (3): E_USER_ERROR: Smarty error: [in pagesvar:pagesitem2en line XXX]…« 01:39 AM
- mesteele101 responded to »Zikula 1.3.3 - Selecting a category in Pages not working« 01:29 AM
- mdee created topic »How to implement returnpage ?« 01:00 AM
- nestormateo responded to »Fillters in Clip« 24. May
- damon responded to »Can the Updated Version Check be Turned Off (Z 1.3)« 24. May
- frw responded to »Bug in the SMTP mail transfer protocol - Port 25 - Zikula 1.2.9« 22. May
- mdee responded to »Short URL questions« 22. May
Zikula Blog
- Anatomy of Open Source Projects on Mar 07
- Continuous Review on Mar 01
- Not Invented Here on Feb 24
- How to Contribute Your Code at Github on Jan 13
- 10 Steps to Coding-Nirvana: Tips for Successful Module Writing on Nov 12
- Submitting Bug Report Tickets That Get Results on Aug 17
- Cozi Tricks #1: Syntax Highlighting on Aug 07
Login
inserting a body onload event handler from a module?
-
- Rank: Helper
- Registered: Apr 08, 2002
- Last visit: Oct 21, 2009
- Posts: 614
-
**unknown user**
- Rank: Registered User
- Registered: Mar 16, 2002
- Last visit: Aug 10, 2004
- 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: Helper
- Registered: Mar 16, 2002
- Last visit: Oct 21, 2009
- 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: Registered User
- Registered: Mar 16, 2002
- Last visit: Aug 10, 2004
- Posts: 45
Thanks,
This helps alot...
I've decided to use a different script as default and include the script and a readme on how to activate the other script.
Thanks for your help and time :) -
**unknown user**
- Rank: Registered User
- Registered: Mar 16, 2002
- Last visit: Aug 10, 2004
- 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: Helper
- Registered: Mar 16, 2002
- Last visit: Oct 21, 2009
- Posts: 676
-
- Rank: Team Member
- Registered: Jan 02, 2003
- Last visit: Oct 21, 2009
- 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: Developer
- Registered: Feb 24, 2003
- Last visit: Nov 12, 2009
- Posts: 254
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...
--
With the advent of modern technology, sites like Twitter, and the Facebook Virus...
I think we should all breathe a collective sigh of relief that I got here in time...
- randomblink
- Moderated by:
- Support
