How to run JavaScript after APP has loaded on page

Solved
Highlighted
Excursionist
22 1 1

Hi folks,

I have a JavaScript function that I trigger using window.onload = function(){myFunction()}; in product-template.liquid.

Now I added an APP (Best Custom Product Options), and I find that my function is run BEFORE the BCPO elements are added to the page, so an element that I want to interact with is undefined.

Does anyone know if there is a way to automatically run my function AFTER the APP has finished adding its elements?

Thanks

0 Likes
Highlighted
Excursionist
46 11 13

This is an accepted solution.

Hello,

Hope you are doing great!

Normally if the app if good coded would have a Event so you can use something like

 document.addEventListener('EVENT FROM APP', function(){
//your code here
});

 

Ask to the support of the app so they can give that information. 

 

Thanks!

 

Regards, Juan

 

◦ Problem Solved? ✔️ Please click on Accept as Solution and like.
◦ Hire me! Worked for 2 years as Shopify Developer.
◦ Contact me at: juansmartdev@beeethereal.com
1 Like
Highlighted
Excursionist
22 1 1

Thanks Juan.  That sounds good.  I'll see what the BCPO support tell me.

Regards, Jack

1 Like
Highlighted
Excursionist
46 11 13

Your welcome

◦ Problem Solved? ✔️ Please click on Accept as Solution and like.
◦ Hire me! Worked for 2 years as Shopify Developer.
◦ Contact me at: juansmartdev@beeethereal.com
0 Likes
Highlighted
Excursionist
22 1 1

In case anyone was interested in the resolution to this, I heard back promptly from BCPO and I just needed to create a function called bcpoDone() and it would run automatically after the APP had finished loading the page:

 function bcpoDone() {

  // insert your code here

}

I'm happy to say this worked first time

0 Likes