MediaOS provides JavaScript methods for programmatically controlling the embedded AI chat experience. These methods allow you more control over things like hiding the floating chat icon and opening the chat interface at the right moment in your user journey.
JavaScript Options #
By default, the embedded AI chat displays a floating icon (usually in the bottom right corner) that users can click to open the chat. But in some cases, you may want more control, such as:
- Hiding the chat icon entirely and launching chat via a custom button or action.
- Automatically opening chat based on a specific page load, user behavior, or support flow.
MediaOS supports both options with two simple JavaScript methods.
Method One #
The window.mosChatHideIcon(true) method should be used when you're looking to hide the default chat icon from your site. It's helpful when you want full control over when and how chat appears, when you're using a custom button or call-to-action elsewhere on the page, or when you want to remove visual clutter and avoid overlapping UI elements.
<script type="text/javascript"> window.mosChatHideIcon(true); </script>
Tip: Call this method early—ideally before or as the MediaOS chat script loads—to prevent flickering or brief visibility of the icon.
Method Two #
The window.mosOpenChat() method can be used to open the chat window programmatically, for example, in response to a button click or page load. It's useful when you want to launch a chat window automatically when a user lands on a help page or performs a specific action.
<script type="text/javascript"> window.mosOpenChat(); </script>
This method is also helpful when you're using a custom UI element (like a "Chat with Support" button) to initiate the conversation.
Combining Both Methods #
To hide the icon and trigger chat programmatically, combine both calls:
<script type="text/javascript"> window.mosChatHideIcon(true); // Hide default icon window.mosOpenChat(); // Open the chat automatically </script>
For example, you could place this in a <script> tag on your "Need Help?" landing page to instantly open chat for a logged-in user without showing the default icon.
Custom Trigger Example #
You can attach mosOpenChat() to any element. Take a button, for example:
<button onclick="window.mosOpenChat()">Chat with Support</button>
This approach allows you to completely brand your chat launcher without relying on the floating chat icon.