How to use a custom JavaScript code to display size charts?

Yes, you can write your own script to display size charts and get content from our app.

To do this you need to subscribe to the prikid_content_ready event, which will be fired when the app receives the size charts for the current product page. The HTML content will be passed in the detail field of the event object

document.addEventListener('prikid_content_ready', function (e) {
    //getting the HTML content of the size chart
    var html_content=e.detail.content;

Then you can inject it wherever you need.

Here is a simple example of a custom script that inserts a button “Open Size Guide” on the top of the page and shows a size chart in the sliding sidebar when you click the button:

   /*Just create a dummy invisible placeholder to prevent auto-placing links/buttons by the app. When the app finds the element with the class 'prikid-size-chart-button-placeholder' it puts the link/button there instead of trying to find the best place automatically. But here we create the placeholder and make it invisible, so the app will put the button here but we won't see it on the page */

    document.addEventListener("DOMContentLoaded", () => {
        var dummy_placeholder = document.createElement("div");
        dummy_placeholder.classList.add('prikid-size-chart-button-placeholder'); = "none";

    // listen for the app's 'prikid_content_ready' event and then place our
    // custom button and the content received from the app
    document.addEventListener('prikid_content_ready', function (e) {
        // Create the button element
        var button = document.createElement("button");
        button.innerHTML = "Open Size Guide";

        // Create the sidebar element
        var sidebar = document.createElement("div"); = "sidebar";

        // Inject size chart content to the sidebar
        sidebar.innerHTML = e.detail.content;

        // adding the sidebar to the document

        // Add styles to the button and sidebar = "fixed"; = "50px"; = '1000'
        button.classList.add('button') = "fixed"; = "0"; = '1000' = `-${sidebar.clientWidth}px`; = "15px"; = "100vh"; = "/docs/latest/does-the-prikid-app-have-an-api-to-get-size-chart-content#f1f1f1"; = "right 0.3s ease";

        // Function to open the sidebar
        function openSidebar() {
   = "0";

        function isSidebarOpen() {
            return === "0"

        // Function to close the sidebar
        function closeSidebar() {
   = `-${sidebar.clientWidth}px`;

        // Add event listener to the button
        button.addEventListener("click", openSidebar);

        // Close the sidebar when clicked outside of it
        document.addEventListener("click", function (event) {
            if (!sidebar.contains( && !== button) {

Use the Storefront -> Script manager to insert the code above into the head of the page (do not forget to wrap the code into the <script></script> tag):

How to use a custom JavaScript code to display size charts? 1

Click Save, and you’ll get the result like this:

How to use a custom JavaScript code to display size charts? 3

Feel free to create a support ticket if you have any difficulties with that

Powered by BetterDocs

Leave a Reply

Your email address will not be published. Required fields are marked *