PDA

View Full Version : onload alternative



GooMoo
09-05-2003, 02:14 PM
i had previously used an onload script to load image rollovers and frames after the initial outside frame had loaded, but a recent test on a machine with a pop-up blocker showed that it prevents onload scripts. while i'm not using it for a popup, the frames targeted for load after the main page stayed in thier loading state. anyone know a way around this? i also noticed that some popup blockers will prevent onclick scripts, i had been using those to target multiple frames to new documents. can onclick also be avoided? i find popup blockers are becoming more and more popular and i'd like my sites to be viewable with them, specially when i don't even have popups.

swstyles
09-05-2003, 05:27 PM
Its hard to believe that the onClick method would be blocked. Its used for so much more than pop up windows. There is a command for javascript to allow the page to load before any javascript gets processed. I forget what it is. What you can do is not call the function but process the preload at the footer of the page so preload is the last thing to happen.



<script>
preload code
</script
</body>
</html>


This is just a theory but it should work fine

GooMoo
09-05-2003, 08:45 PM
Nah that wouldn't work, thanks though. The html and javascript is read and executed well before the graphics are even partially downloaded, that's why you can view source after the images start to load but before they are finished loading. A script fired onload goes after all html and graphics are loaded. i found it tough to swallow too but yes onclick is blocked by some popup blockers.

orvadotech
09-07-2003, 11:51 PM
Just a thought...

If you place a "SCRIPT" block at the end of your page (before the close body or close html tag), you can call a javascript function which does all of the loading of the content. This should be equivalent to the "onLoad" event which is fired after all of the HTML has loaded.

mixdev
09-08-2003, 09:12 AM
orvadotech, this Technique is good for some specialised apps like my
http://www.amacement.com/senselabs/keyword_analyzer.php

this keyword analyzer is coded such a way that it will start processing ONLY after the form elements are loaded(using settimeout function).

But in this case it wont be good, because we want to load the imgs as soon as possible AND want to escape from adblockers. So as a solution for this, its good to use a external .js file having a document.onload handler code in it.

<SCRIPT language="JavaScript" src="openCode.js"></script>

and openCode has code like.....



function open_sisame(){
//code to do something on pageload follows
.............
.............
return 1;
}

// add the handler here
document.onload = open_sisame();



This would be enough to passthrough the nasty ad-block apps...i think

swstyles
09-08-2003, 11:41 AM
take your preload function code out of the function itself and your images will load as soon as the page is rendered up to that point in your code.

johndodrill
02-28-2004, 02:53 AM
Even though I'm only a novice, I think I've tried all of those things only to find out that different browsers (Netscape, IE, Opera, Firefox, Mozilla) respond differently to onload="whatever" and windows.onload = 'whatever'; and they process JavaScript at different times with respect to HTML.

So... I just estimate the first-time load time on the high side and use a timer.


Here's the meat of it (though I'm sure you already know this):


/* set up a timer with load time in milliseconds */
myTimerset = true;
mytimerid = window.setTimeout("myFunction()", 50000);


Then my function does this:


function myFunction()
{
/* Clear the timer so you could use it again */
if (myTimerset == true)
{
clearTimeout(mytimerid);
myTimerset = false;
};

/* whatever afterload processing you want goes here, ie. */

document.images.myImage.src = "myImage.gif"

};



I hope this isn't too far astray of what you guys are trying to do.

It works for me on http://john.dodrill.name. I load all images as static images, to get the screen painted, then use a timer to load a rotating .gif at the top of the page.

On http://john.dodrill.name/socalemployers, I have to wait until all frames are loaded before I can start seting inter-frame variables, so I use this technique.

Hope this helps. By the way, these are all just my personal pages I'm toying with so don't look to be impressed.