Articles on: Advanced

How to run custom JavaScript when app is ready?

How to run custom JavaScript when the website is ready?

Sometimes you need to run some JavaScript code after the website is fully rendered and all elements are ready for interaction.
If you run the code too early (before the web app is fetched all the data and complete rendering) most likely some elements will be missing or lack data.

That's why there is a special event ssViewerRendered

<script>
document.addEventListener('ssViewerRendered', () => {
  // put your code here
})
</script>



A working example that opens the details page by clicking on any part of a product card:

<script>
document.addEventListener('ssViewerRendered', () => {
  document.querySelectorAll('.sv-tile').forEach(tile => {
      tile.querySelector('.sv-tile__image').onclick = () => tile.querySelector('.sv-tile__btn').click()
  })
})
</script>


This code should be added in Settings tab.

Updated on: 06/03/2023

Was this article helpful?

Share your feedback

Cancel

Thank you!