# AI Chatbot: How to keep the chat window open on each page load

**URL:** https://community.elfsight.com/t/ai-chatbot-how-to-keep-the-chat-window-open-on-each-page-load/140271
**Category:** Pro Tips
**Tags:** ai-chatbot
**Created:** [October 3, 2025, 11:47am UTC](https://community.elfsight.com/t/ai-chatbot-how-to-keep-the-chat-window-open-on-each-page-load/140271 "2025-10-03T11:47:58Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Max](https://sea2.discourse-cdn.com/flex020/user_avatar/community.elfsight.com/max/32/710_2.png) [@Max](https://community.elfsight.com/u/Max)
#### Post date: [October 3, 2025, 11:47am UTC](https://community.elfsight.com/t/ai-chatbot-how-to-keep-the-chat-window-open-on-each-page-load/140271/1 "2025-10-03T11:47:58Z")

</div>

Want to keep the chat window of your [AI Chatbot](https://elfsight.com/ai-chatbot-widget/) widget open on page reload or when switching pages of your website? Our devs found a great solution!

Just add this code to the **Custom JS** field on the **Settings** tab of your widget’s settings and you’ll be fine:

```auto
function waitForElement(selector, root = document) {
    return new Promise((res) => {
        let i = 10;

        function check() {
            const component = root.querySelector(selector);

            if (component) {
                res(component);
            } else if (i !== 50) {
                setTimeout(check, 100);
                i++;
            }
        }

        check();
    });
}

waitForElement("[class*='eapps-ai-chatbot'] button").then((bubble) => {
    const portal = bubble.parentNode.parentNode;
    
    const openChat = () => {
        const window = portal.querySelector("[class*='window-transition__Container-sc']");
        if (!window) {
            bubble?.click();
        }
    };
    
    openChat();
});

```

  

> **Note:** Custom JS doesn’t function in the preview mode, so you can check the result right on your website or through the [Share Link](https://help.elfsight.com/article/1471-how-to-share-widget-via-link)

  

Guys, was this solution helpful? Let us know in the comments 🙂
