Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Safari browser javascript problem
Old 03-29-2007, 09:51 AM Safari browser javascript problem
Junior Talker

Posts: 1
Trades: 0
The page appears when all the images are loaded, it works in all browsers less in SAFARI.
<script language="javascript">
<!--
function precargar() {
imgs = document.images;
precargadas = true;
for (var i = 0, total = imgs.length; i < total; i ++)
precargadas = (precargadas && imgs[i].complete);
if (precargadas) {document.body.style.visibility = "visible";}
else setTimeout("precargar()", 100);
}
//-->
</script>
<body onload="precargar()" style="visibility:hidden;">
</body>
The problem can be in:
Document.body.style? Safari does it refer otherwise to body?
Thank you for attending my problem.
rwcamera is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-31-2007, 09:41 PM Re: Safari browser javascript problem
logic ali's Avatar
Super Talker

Posts: 104
Trades: 0
Quote:
Originally Posted by rwcamera View Post
The page appears when all the images are loaded, it works in all browsers less in SAFARI.
<script language="javascript">
<!--
function precargar() {
imgs = document.images;
precargadas = true;
for (var i = 0, total = imgs.length; i < total; i ++)
precargadas = (precargadas && imgs[i].complete);
if (precargadas) {document.body.style.visibility = "visible";}
else setTimeout("precargar()", 100);
}
//-->
</script>
<body onload="precargar()" style="visibility:hidden;">
</body>
The problem can be in:
Document.body.style? Safari does it refer otherwise to body?
Thank you for attending my problem.
Any console errors?

If Safari succeeds in hiding the page with CSS, presumably using visibility:hidden, it must accept document.body.style.visibility = "visible";

Have you tried alerting precargadas in the function?

This code is flawed because the final value of precargadas is dependent solely upon the .complete property of the last image.

Code:
for (var i = 0, total = imgs.length; i < total && imgs[i].complete; i ++)
;

precargadas= i==total;

if (precargadas)
 {document.body.style.visibility = "visible";}
else 
 setTimeout("precargar()", 100);
Although even this is inadvisable because a load failure of any image will prevent display of the page.
Setting a timeout is pointless because the function is being called by the onload event, which fires when all images are either loaded or their loading has been abandoned.

I recommend using a script statement in the head section to hide the page initially (not CSS), then using the onload event to set the visibility of the page, regardless of the images' load status.
logic ali is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Safari browser javascript problem
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.74572 seconds with 12 queries