cancel
Showing results for 
Search instead for 
Did you mean: 

Document onload

Document onload

$(document).ready(function(){somefunk_from_external_script();});

OK i am having one heck of a time. I have spent weeks looking for any accurate documentation on Magento2 modules. A few exist but they dont cover how i might get something as simple as the above code.

Feel free to point me to some seemingly obvious answer  but i really need to have it wait till the entire DOM is loaded. This wouldnt be an issue but Magento2 seems to load JS files before HTML


Charlie Simmons
Developer
Payment Processing, Payroll Solutions and Rewards
One Heartland Way
Jeffersonville, IN 47130
HeartlandPaymentSystems.com facebook.com
3 REPLIES

Re: Document onload

I recommend to place your initial JavaScript into x-magento-inithttps://mage2.pro/t/145

Then, you can load other JavaScripts as AMD modules using RequireJS: https://mage2.pro/t/141

I recommend to use the the domReady! dependency in an AMD module to ensure the DOM is loaded: https://mage2.pro/t/540

Re: Document onload

thank you Dmitry
I think the 3rd link you posted is what i was looking for. I will test and accept the answer assuming things go well

Charlie Simmons
Developer
Payment Processing, Payroll Solutions and Rewards
One Heartland Way
Jeffersonville, IN 47130
HeartlandPaymentSystems.com facebook.com

Re: Document onload

No good. I have resolved to checking for an element to exist and if not aborting to call. The code just keeps getting called until the page does load. I wonder why Magento developers assume everyone understands their API. I wonder if posting meaningful documentation for single developer shops is being withheld to extort training fees?. To do anything in Magento 2 it seems you must resolve to reverse engineer. but this is a very incomplete tactic. Every other ecom and cms has extensive straight forward documentation. Why is it so hard to do the simple stuff

 


Charlie Simmons
Developer
Payment Processing, Payroll Solutions and Rewards
One Heartland Way
Jeffersonville, IN 47130
HeartlandPaymentSystems.com facebook.com