Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.onload function doesn't work on Mozilla Firefox

I'm using a loading screen for a webpage and I use window.onload function.

Everything works great except in Mozilla Firefox browsers. When we first visit or refresh the page with ctrl+F5 combination, the loading screen never disappears. if we refresh the page only with F5, then it works.

I use the code below

$(window).load(function(e) {
    $("#body-mask").fadeOut(1000,function(){
        $(this).remove();
    });
});

I have also tried the code below but nothing changed.

window.onload = function () {
   $("#body-mask").fadeOut(1000,function(){
       $(this).remove();
   });
}

Why this is happening?

Please help.

Thanks in advance.

like image 842
Onur Kucukkece Avatar asked Apr 01 '13 15:04

Onur Kucukkece


People also ask

Can I use window onload?

window. onload just runs when the browser gets to it. window. addEventListener waits for the window to be loaded before running it.

How does window onload work?

The window. onload property is created by the browser and exists by default. By default is has a value of null . But, if you assign a function to it (so it contains a valid function instead of null ), then the browser will call that function when the page resources have finished loading.

Does document onload and window onload fire at the same time?

The general idea is that window. onload fires when the document's window is ready for presentation and document. onload fires when the DOM tree (built from the markup code within the document) is completed.

What is the difference between window onload and document ready?

The $(document). ready() is a jQuery event which occurs when the HTML document has been fully loaded, while the window. onload event occurs later, when everything including images on the page loaded. Also window.


2 Answers

The problem is caused by another jquery background plugin which is placed inside $(document).ready()

I moved it inside $(window).load() function, now it works perfect.

I have also moved another function to resize images on the page load. When it was inside $(document).ready() block, sometimes it was malfunctioning if loading time took too long but now it also works great.

function resizeImages(){
    //Some Code
}

$(window).load(function(){
    $("#body-mask").fadeOut(1000,function(){
        $(this).remove();
    });

    $.vegas({
        src: backURL , fade:0
    });

    resizeImages();
});

$(document).ready(function(){
    //Some Other code
});
like image 182
Onur Kucukkece Avatar answered Sep 18 '22 13:09

Onur Kucukkece


I got the same problem when mistyped the type attribute in the script tag:

<script type="text/javascript">
like image 35
bandolero Avatar answered Sep 21 '22 13:09

bandolero