Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Window load function does not work on Safari

When using Safari (Version 11.1 (13605.1.33.1.4)) every window event functions that I have tried are not working:

Pure JavaScript:
window.addEventListener('load', function() { // code here });
window.onload = function() { // code here };

jQuery
$(window).on('load', function() { // code here });
$(window).load(function() { // code here });

I don't want to use document ready functions, because I have to wait till all images are loaded on the page. If you have something other in mind, please feel free to discuss.

like image 320
George Stoilov Avatar asked Aug 18 '26 13:08

George Stoilov


1 Answers

How about this?

if (document.readyState === 'complete') {
  callback();
} else {
  window.addEventListener('load', callback);
}
like image 175
scrhartley Avatar answered Aug 21 '26 04:08

scrhartley