Hi. I’m integrating a LeadBooster chat bot into a React page.
Following these instructions I’ve got it loading, and it works great.
Now, I need to be able to hide the chat bot under certain conditions.
Not minimize the chat window down to just the icon: hide it completely, icon and all. Make it not visible on the page, full stop.
document.getElementById('LeadboosterContainer').style.display = 'none';
document.getElementById('LeadboosterContainer').style.display = 'none !important';
No effect. Looking at the element in dev tools, it doesn’t event add the style to the iframe element.
visbility: 'hidden !important'.
right: '-5000px !important'.
An alternate approach would be if I could get the iFrame to attach itself to the DOM inside an element that I specify, like so:
<iframe id="LeadboosterContainer" ... ></iframe>
Then I could just hide the container element as needed.
Other insertable widgets follow this pattern: either creating the iframe inside a div, or allowing you to specify the id of an element to add the iframe to.
But I can’t find anywhere in the docs that allows me to specify such a thing.
Any insight would be very appreciated.
Thanks in advance!
Chatbot (LeadBooster) creates CSS that guarantees appearance via
!important rule in CSS.
If a page reload does not matter (as ChatBot script will appear again), to hide it programmatically on the frontend you could use something like this
document.getElementById('LeadboosterContainer').setAttribute('style', 'display:none !important');
In other cases, I would suggest adding/skipping the ChatBot script on the backend instead, so if “hiding” conditions are met, ChatBot script is not included in the page response, hence ChatBot is not rendered and no need to hide it on the frontend.
I kinda figured that would be the case.
We really don’t want the user to suffer a page reload.
Also, we’re not doing any server side rendering. All of our pages are statically rendered or client side rendered (we’re using Gatsby), so the server rendering won’t work either.
Here’s what I’ve come up with. When the component responsible for managing pipedrive chat unmounts the first time, we create a new div as a container for the pipedrive chat bot iframe, move the iframe to its new container, then hide the container:
const pipedriveContainer = document.createElement('div');
pipedriveContainer.id = 'pipedrive-container';
const pipedriveFrame = document.getElementById('LeadBooster');
pipedriveContainer.style.display = 'none';
Then, in the future, when the same component mounts:
document.getElementById('pipedrive-container').style.display = 'block';
And every subsequent time it unmounts, it just hides the container again.
I don’t love this solution but it works, and doesn’t have any undesired UI/UX side effects.