# Activating Hubspot Chat via Javascript

**URL:** <https://community.hubspot.com/t/activating-hubspot-chat-via-javascript/15587>\
**Category:** CMS Development\
**Created:** [August 2, 2019, 2:17pm UTC](https://community.hubspot.com/t/activating-hubspot-chat-via-javascript/15587 "2019-08-02T14:17:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kove](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kove/32/102153_2.png) [@kove](https://community.hubspot.com/u/kove)\
**Post date:** [August 2, 2019, 2:17pm UTC](https://community.hubspot.com/t/activating-hubspot-chat-via-javascript/15587/1 "2019-08-02T14:17:06Z")

</div>

in the menu we have a icon (chat), this should trigger a click (via Javascript) in the lower right corner (where the chat icon from hubspot is located).  
So the chat should be reachable from within the menu. but the URL from the chat (iframe) is different than that one from the website, which means it gets blocked by the browser (crossside scripting). My question, how can i toggle the chat icon from within the page if i DONT want to click on the icon in the lower right corner directly.

---

<div class="post-metadata">

**Author:** ![Jenny](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jenny/32/24_2.png) [@Jenny](https://community.hubspot.com/u/Jenny)\
**Post date:** [August 22, 2019, 7:12pm UTC](https://community.hubspot.com/t/activating-hubspot-chat-via-javascript/15587/2 "2019-08-22T19:12:27Z")

</div>

Hi @kove,

Do you mind sharing a link to the page you are working on and any troubleshooting you have done so far?

The more information, screenshots and details you can provide, the better the Community can assist!

Thank you,  
Jenny

---

<div class="post-metadata">

**Author:** ![kove](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kove/32/102153_2.png) [@kove](https://community.hubspot.com/u/kove)\
**Post date:** [August 23, 2019, 6:43am UTC](https://community.hubspot.com/t/activating-hubspot-chat-via-javascript/15587/3 "2019-08-23T06:43:11Z")

</div>

Hey [@jennysowyrda](https://community.hubspot.com/t5/user/viewprofilepage/user-id/3685)

This would be the page  
[http://business4you-2482957.hs-sites.com/family](http://business4you-2482957.hs-sites.com/family)

Thanks for your help

---

<div class="post-metadata">

**Author:** ![Teun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/teun/32/28739_2.png) [@Teun](https://community.hubspot.com/u/Teun)\
**Post date:** [August 27, 2019, 5:49am UTC](https://community.hubspot.com/t/activating-hubspot-chat-via-javascript/15587/4 "2019-08-27T05:49:11Z")

</div>

Hi Kove,

You could register a click event listener to the element in the menu and use the Conversations API to open the chat widget: [https://developers.hubspot.com/docs/methods/conversations\_api/hubspot-conversations-javascript-api](https://developers.hubspot.com/docs/methods/conversations_api/hubspot-conversations-javascript-api)

Here is an example of how it could work:

```auto
const element = document.querySelector('.element') // Use an ID or class to get your element

element.addEventListener('click', e => {
 if (window.HubSpotConversations) {
 window.HubSpotConversations.widget.open()
 } else {
 window.hsConversationsOnReady = [
 () => {
 window.HubSpotConversations.widget.open()
 }
 ];
 }
});

```

To close the chat you can use:

`window.HubSpotConversations.widget.close();`
