Click to See Complete Forum and Search --> : Question about !document.all


karl
09-17-2003, 07:52 PM
Hello !

I just got a nice image preloading script with a progress bar working, but now I have a problem I cant solve. I need a redirection to another page after preload is finished. I have put this code in the script section:

var locationAfterPreload = "http://www.xxxxxxxx.com"
if (!document.all) location.replace(locationAfterPreload)

But it wont get directed. Have I done something wrong left a couple of ;} signs or something behind ? It seem to work as explorer is not complaining but I wont get directed. If anyone could help me out with this script or simply got a better solution(a better script). Please reply to me.

Thanks for any help !

/Karl

Khalid Ali
09-17-2003, 09:29 PM
try using

window.location.replace = url

karl
09-18-2003, 05:36 AM
Hello and thanks for the reply .. but I cant get thatone to redirect the page either.

Charles
09-18-2003, 06:03 AM
1) You've got to keep things working for the 13% of users who do not use JavaScript.

2) "location.replace(someUrl)" will send you to some url but are calling it if not "document.all". That's an object present in MSIE, so your condition is always false in MSIE.

<script type="text/javascript">
<!--
images = ['http://forums.webdeveloper.com/images/smilies/smile.gif', 'http://forums.webdeveloper.com/images/smilies/frown.gif', 'http://forums.webdeveloper.com/images/smilies/redface.gif'];

imagesLoaded = 0;

for (i=0; i<images.length; i++) {
o = new Image();
o.onload = function () {if (++imagesLoaded == images.length) location.replace('http://www.w3.org')};
o.src = images[i];
}
// -->
</script>
<noscript><a href="http://www.w3.org">W3C</a></noscript>

karl
09-18-2003, 10:21 AM
Below is the code I use to my page if I could get some help including the redirect part after images is loaded. I use var locationAfterPreload = "startpage2.htm" in the code.

<script language="JavaScript">

/*
Progress Bar
Copyright Eddie Traversa (nirvana.media3.net)
To add more shock to your site, visit www.DHTML Shock.com
*/

//PUT THE NAMES OF ALL YOUR IMAGES IN THE ARRAY BELOW.
var locationAfterPreload = "startpage2.htm"
var imagenames=new Array('images/mainpicture1.jpg','images/mainpicture1.jpg','images/mainpicture1.jpg','images/mainpicture3.jpg','images/mainpicture4.jpg','images/mainpicture5.jpg','images/mainpicture6.jpg','images/mainpicture7.jpg','images/mainpicture9.jpg','images/mainpicture10.jpg');
var yposition=120; //POSITION OF LOAD BAR FROM TOP OF WINDOW, IN PIXELS
var isNS=(document.layers);
var _all = (isNS) ? 'outer.document.' : 'all.' ;
var _style = (isNS) ? '' : '.style';
var _visible = (isNS) ? 'show' : 'visible' ;
var _hidden = (isNS) ? 'hide' : 'hidden' ;
var blocksize=Math.ceil(250/imagenames.length);
barwidth=imagenames.length*blocksize;
var images=new Array();
var loaded=0, txt='';

function resize(){
if(isNS){
document.outer.moveTo( window.innerWidth/2-barwidth/2 , yposition );
}else{
document.all.outer.style.pixelLeft=document.body.clientWidth/2-barwidth/2;
document.all.outer.style.pixelTop=yposition;
}}

txt+=(isNS)? '<layer name="outer" height="22" bgcolor="lightgrey" top="'+yposition+'" left="'+(window.innerWidth/2-barwidth/2)+'" width="'+barwidth+'" visibility="visible">' : '<div id="outer" style="position:absolute; left:'+(document.body.clientWidth/2-barwidth/2)+'; top:'+yposition+'; height:22px; background-color:lightgrey; width:'+barwidth+'px; visibility:visible;">';
txt+=(isNS)? '<layer z-index="2" width="'+barwidth+'" height="22" ><font point-size="12"><center>Images loading...</center></font></layer>' : '<div style="position:absolute; text-align:center; height:22px; width:'+barwidth+'px; z-index:100; font-size:14px; ">Images loading...</div>';
txt+=(isNS)? '<layer z-index="1" name="prog" height="22" bgcolor="lightseagreen" width="0"></layer>' : '<div id="prog" style="position:absolute; height:22px; background-color:lightseagreen; width:0px"></div>';
txt+=(isNS)? '</layer>' : '</div>';
document.write(txt);

resize();

function dispbars(){
loaded++;
if(isNS){
document.outer.document.prog.clip.width=blocksize*loaded;
}else{
document.all.prog.style.width=blocksize*loaded;
}
if(loaded>=imagenames.length){
setTimeout('(isNS)?document.outer.visibility="hide":document.all.outer.style.visibility="hidden";', 800);
}}

function loadimages(){
for(n=0;n<imagenames.length;n++){
images[n]=new Image();
images[n].src=imagenames[n];
checkload(n);
}}

function checkload(index){
(images[index].complete)? dispbars() : setTimeout('checkload('+index+')', 500);
}


window.onload=loadimages;
window.onresize=resize;
</script>

DiScOmBoBuLaToR
10-08-2003, 05:37 PM
1) You've got to keep things working for the 13% of users who do not use JavaScript.

2) "location.replace(someUrl)" will send you to some url but are calling it if not "document.all". That's an object present in MSIE, so your condition is always false in MSIE.

<script type="text/javascript">
<!--
images = ['http://forums.webdeveloper.com/images/smilies/smile.gif', 'http://forums.webdeveloper.com/images/smilies/frown.gif', 'http://forums.webdeveloper.com/images/smilies/redface.gif'];

imagesLoaded = 0;

for (i=0; i<images.length; i++) {
o = new Image();
o.onload = function () {if (++imagesLoaded == images.length) location.replace('http://www.w3.org')};
o.src = images[i];
}
// -->
</script>
<noscript><a href="http://www.w3.org">W3C</a></noscript>

i was wondering if this would work for music files like wma by replacing the image files' url with the url of the music file. does anyone no if it might work?