Tuesday, 24 March 2009

Javascipt onload confclits

Normally there are two ways to run javascipt when html page is loaded:

  1. window.onload=INLINE_FUNCTION_NAME, is normally used to make specific javascript runnable when the html document is loaded.
  2. general javascript function, like "function FUNCTION_NAME() {... }; FUNCTION_NAME();"
The problem of method 1) is that one page only can have one onload function. there are always conflicts in Joomla or drupal which use a lot of javascript for functions.

The problem of method 2) is that when the function started, maybe the html document is not fully loaded.

FIX
===============================
To solve this, 'domready' from mootools helps a lot and improves the loading speed very much. See domready vs load.
Insert mootool.js (optional for Joomla, But required for local html test)
---------------------------------------------------
<script type="text/javascript" src="mootools.js">
</script>

---------------------------------------------------
You should go to mootools.net to download the latest mootools.js.

No comments:

My photo
London, United Kingdom
twitter.com/zhengxin

Facebook & Twitter