Contact Us

Why Wait for a Page to Load Before Running Your Code?

There are a few different situations you may encounter where you will need to wait for a SuiteCommerce page to finish loading before running your code. Reasons could include:

  • Waiting for some other content to load
  • Need all page elements to be present
  • etc.

Solution: 'afterShowContent' Functions and Listeners

Various parts of the site implement “afterShowContent” functions and listeners. See the examples below for which may work best for your use case. This code should almost always be written in an entry point file or function run in an entry point file.

'afterShowContent' Code Sample

define('Example.EntryPoint', [], function (){ 'use strict'; return { mountToApp: function mountToApp (container) { //Wait for the PDP to load to ensure you have access to the item data const PDP = container.getComponent('PDP'); PDP.on('afterShowContent',function() { let itemInfo = PDP.getItemInfo(); }); //Similar logic applies to the PLP const PLP = container.getComponent('PLP'); PLP.on('afterShowContent',function() { let items = PDP.getItemsInfo(); }); //The general site layout components can be used to run //code after any page site wide has finished loading const Layout = container.getComponent('Layout'); Layout.on('afterShowContent',function(viewName) { //do someting here }); } }; });

Got stuck on a step in this article?

We like to update our blogs and articles to make sure they help resolve any troubleshooting difficulties you are having. Sometimes, there is a related feature to enable or a field to fill out that we miss during the instructions. If this article didn't resolve the issue, please use the chat and let us know so that we can update this article!

Oracle NetSuite Alliance Partner & Commerce Partner

If you have questions about how our team can support your business as you implement NetSuite or SuiteCommerce, feel free to contact us anytime. Anchor Group is a certified Oracle NetSuite Alliance Partner and Commerce Partner equipped to handle all kinds of NetSuite and SuiteCommerce projects, large or small!

Horizontal Anchor Group logo orange anchor icon navy Anchor Group text

Tagged with Training