$(window).load function is not working

Tourist
12 0 1

Hi, I tried to implement a preloader with jquery. I want to hide it when the window is loaded. but it isn't working. Then I tried a simple function to tes, unfortunatly it is not working too. 
I don't know why (window).load function is not working in Shopify.

$(window).load(function() {
  alert("window is loaded");
});

0 Likes

Hi Gince,

You should use the following code:

1:

$(function(){
  alert('loaded');
})
2:

function ready() {
  alert( 'Loaded' );
}

document.addEventListener("DOMContentLoaded", ready);
3:

window.onload = function() {
  alert( 'Loaded' );
};

jquery is used in the 1st case and js in the 2nd and 3rd.

I hope it helps.
Best,
Arthur

Shopify subject matter expert | Founder at GenovaWebArt | Full-services shopify agency | info@genovawebart.com
1 Like
Highlighted
Tourist
12 0 1

The 3rd one worked, thanks man.

0 Likes
New Member
10 0 0

Problem with solution one:

 

for whatever reason, jquery seems to be on a delayed load. Any attempt to run the jquery 'ready()' function at or before the document has loaded product "$ is not defined" (or jQuery is not defined if you call it with the full name)


Problem with solution two:

for whatever reason, jquery seems to be on a delayed load. If whatever script you are calling uses jquery in any way, you will again get "$ is not defined"


Problem with solution three:

if something else has added a window.load behavior elsewhere on the page, you have just over-rode it with your window.load, potentially stepping on code that is trying to do something similar elsewhere on the page. Also the same problem with solution two exists in that if any of your code calls jquery, it's going to say '$ is not defined'

0 Likes