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");
});
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
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'
Subject | Author | Posted |
---|---|---|
43 seconds ago | ||
12m ago | ||
29m ago | ||
57m ago | ||
an hour ago |
User | Count |
---|---|
323 | |
77 | |
72 | |
65 | |
56 |