I am integrating an app into Shopify. I am currently testing our external js file. We are seeing some weird results. When I use this code:
jQuery(document).ready(function(){
console.log("hi");
});
the "hi!" appears in the console. But when I use:
window.onload = function() {
console.log("hi!");
}
...nothing happens. I am speculating that there is another onload event handler which happens later and overwrites mine, but even if I try to do the jquery equivalent in js:
window.DOMContentLoaded = function() {
console.log("hi!");
}
...still nothing happens. Any ideas why this is, and is there a way to get my script to function with an equivalent of (document).ready without having to resort to jQuery (since some customers may not be running it)?
Did you try this?
The
window.onload
could be overwritten by your last allocation. You should not use it. You must useaddEventListener
which will put all your functions attached into a queue and later all those functions will be executed.