FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

Is this javascript valid?

 


Technaut
i just want to be sure this is valid and will work, since i don't normally use javascript:

Code:
<body onLoad="document.googleFrm.query.focus(); if ('Navigator' == navigator.appName) document.forms[0].reset();">


i am making a private homepage for myself, with different scripts embedded, such as a pop3 mail checker, and a custom google search engine (things i use allot), and i want to be sure the search has focus when the page loads, and that the page also is not cached in Navigator (i used other code to skip the cache on IE).
Mosquito.Tyler
You can only call functions in events, you cannot run commands like if/then I don't think. Depending on how your other code is set up, it may simplify things to just call functions anyway.
Ranfaroth
onLoad is invalid. The real syntax is onload.
But the onaction attributes should be avoid (they have many problems)
Events must me attached with the script language.

Just separe the script instructions from the content of your page...
sb3700
your code is perfectly valid and will work perfectly.

attributes are case-insensitive so onLoad is the same as onload

generally, onLoad is easier to read, but in XHTML, all attributes must be lower-case so onload is technically more correct.

however, you should separate content from presentation and from behaviours (see: http://kurafire.net/log/archive/2005/04/26/on-separating-style-and-behaviour or http://formassembly.com/blog/ajax-and-the-true-separation-of-code-and-content/) so you should have a window.onload handler in a script either externally or in the head section

ie:
Code:
window.onLoad = function(){
  document.googleFrm.query.focus();
  if ('Navigator' == navigator.appName) document.forms[0].reset();
}


or use something like this if you want to add other onLoad events:
Code:
function doStuff(){
  document.googleFrm.query.focus();
  if ('Navigator' == navigator.appName) document.forms[0].reset();
}
addLoadEvent(doStuff)

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}


Note: addLoadEvent from: http://simon.incutio.com/archive/2004/05/26/addLoadEvent
Ranfaroth
sb3700 wrote:
attributes are case-insensitive
Not in XHTML Rolling Eyes
Reply to topic    Frihost Forum Index -> Scripting -> Html, CSS and Javascript

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.