codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Multiple onload not working?  Vince at 17:32 on Wednesday, April 29, 2009
 

Multiple onload is not working on I.E. 8 or Firefox,
does anyone have a fix?

I am tring to load multiple events, and I only get one back in two places?

<Added>

<script type="text/javascript">
<!--
onload=function() {
postaction('1');
postaction('3');
}
//-->
</script>

this does not work!

<Added>

<script type="text/javascript">
<!--
function start() {
postaction('1');
postaction('3');
}
//-->
</script>

<BODY onload="start();">

This does not work either -

or this:

<BODY onload="postaction('1'); postaction('3');">

  Re: Multiple onload not working?  jessonerik at 05:53 on Wednesday, October 14, 2009
 

The window.onload problem has been proclaimed solved before but I've had issues with the brittleness of the proposed solutions due to browser sniffing and dependency on non-standard behavior. Even if the sniffing and hacking are accepted the problem has never really been solved anyway . I've been seeking a robust solution to use unobtrusive JavaScript techniques and I think at 4 am this morning I discovered one real estate agent. I don't know why these things have to happen at 4 am but I do know I'd rather be sleeping.

In my previous window.onload article I looked at four techniques: bottom script, Dean Edwards, DOM polling and global delegation. Each had problems.

The first three techniques (bottom script, Dean Edwards and DOM polling) share a common fault. When the page is loaded, there is a period of time where elements are left "exposed". By exposed I mean the elements are visible and the user can interact with the elements but event handlers have not yet been attached. This period of exposure is short for most documents and that is why these techniques have worked acceptably for many developers. However the fact that there is exposure means the solutions are not as robust as using old-fashioned inline HTML event attributes mortgage rate. So regardless of implementation, these three techniques are not solutions.

In the comments to my previous article, Jesse Rudderman pointed out the above flaw with the first three techniques. He suggested

How about taking advantage of event bubbling instead of trying to attach an event hander to the element in time? That is, add a global onclick handler and look to see if event.target or event.originalTarget is one of the elements you're interested in. For hover effects you can do the same with onmouseover.

After his comment, I updated my previous article to look at a possible implementation and implications of his idea. With a roll-your-own event system Jesse's idea completely solves the problem for bubbling events. But what about those non-bubbling events?

I give up. I do some real work. Months pass...

Then yesterday I came across Brandon Aaron's Live Query plugin for jQuery. I'm not very familiar with jQuery but his idea is very interesting. With his plugin you can write the following unobtrusive JavaScript.

$('input[type="text"]').livequery('focus', function() {
alert('a text input has been focused'); home mortgage
});

If a new text input is added to the page using the jQuery DOM manipulation functions, then Brandon's plugin will attach the focus handler. How cool is that? This is part of the total unobtrusive JavaScript solution. This provides something similar to Internet Explorer's CSS expressions but Brandon's solution is a whole lot better. But the picture isn't complete. Those input[type="text"] elements still sit exposed during the page load as jQuery uses the Dean Edwards technique.

For non-bubbling events the event handlers must be attached to the elements themselves since there is no option for delegation. In order to attach the handlers the elements must be parsed and in the DOM. If they are in the DOM that means they are likely visible and hence exposed. It seems like an insoluble problem.

Usually before an element is focused, a bubbling event occurs (e.g. keypress, mousedown). When the Edwards technique says "go", jQuery runs a function called jQuery.ready(). This function could be run each time one of these bubbling events occurs that might precede non-bubbling event. Then the non-bubbling event handlers will be attached to the appropriate element when the non-bubbling event fires an instant later. It turns out that in Internet Explorer a user can tab to an input without a keypress event firing. So that idea out the window.

Then I think, "Ok, I'll use Jesse's solution for all bubbling events and for the very few non-bubbling events I use, I'll just use inline handlers."

And then the gears in my head (that apparently desperately need some grease) finally compute 2 + 2.

Have you read Dan Cederholm's Bulletproof Web Design? You really should. It is an outstanding example of a tutorial-type text book. Dan believes in separation of content and presentation. No border or align attributes in his HTML. That's the job of CSS. It must have tormented him that he couldn't find a way to use CSS to "null" the cellspacing attribute. I bet he tried at length. So what did he do? He compromised purity. For every table I've written since I read Dan's book I've followed his advice and started with bad credit personal loans

<table cellspacing="0">








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
• C++
• Re: refresh parent after closing pop up window
• Dynamic Insertion
• Date and Time function around the world???
• Significant Factors
• Perl array access
• Re: huffman encoding and decoding in C++...
• Perl One Liner: Replace {(
• Re: html including php, accessing the functions


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2009