Possibility to open the chat window by using custom button/js
It could be nice to have a possibility to open/expand the chat window by clicking on a custom button. Plenty of people would like to have (and need) this option.
This triggers the chat window to open, which might be useful to some of you.
That is the only piece of the 'experimental API' that exists. There is no way to close the window and there are no callbacks to notify you if the chat window is opened, closed, resized etc. or to toggle targeted messages. I had to implement a resize observer to achieve those.
Hi all, I'm very pleased to announce that we now have the ability to open the chat launcher by appending #hs-chat-open to your URLs, or by adding that as an anchor link tag on any buttons/links/etc. on your page. The team is also working on some more sophisticated solutions to enable the same behavior with custom CSS elements. I will update here when that goes live as well, but please enjoy the new functionality if you've been waiting for it! Details here: https://knowledge.hubspot.com/articles/kcs_article/conversations/how-to-use-conversations#automatica....
We have found a very easy solution. Watch the video to see the solution.
You can use the Javascript code below:
// logo-btn is ID for the element assigned with click event to show Hubspot chat window
// jQuery (ES6)
$('#logo-btn').on('click', () => {
// check if Hubspot chat is installed
if (window.hubspot_live_messages_running && window.hubspot && window.hubspot.messages) {
window.hubspot.messages.EXPERIMENTAL_API.requestWidgetOpen();
} else {
console.log('Please install HubSpot WordPress plugin');
}
});
// VanillaJs (ES5)
document.getElementById('logo-btn').addEventListener('click', function(event) {
// removef if it is no need to prevent default event such as url redirect in the <a> element
event.preventDefault(true);
// check if Hubspot chat is installed
if (window.hubspot_live_messages_running && window.hubspot && window.hubspot.messages) {
window.hubspot.messages.EXPERIMENTAL_API.requestWidgetOpen();
} else {
console.log('Please install HubSpot WordPress plugin');
}
});