The widget
The widget is a small script, about 9 KB gzipped. It draws the chat in a shadow root, so your page's CSS does not change it and its CSS does not change your page. It uses no iframe and no third-party cookies.
Embed code
<script src="https://desk.casdoor.com/widget.js" data-site="example-com" async></script>Put it into every page, before </body>. On pages without it, the chat does not show, and visits to those pages are not tracked.
| Attribute | Meaning |
|---|---|
data-site | The site's name (required) |
data-lang | en or zh. By default the site's language setting, or the visitor's browser language |
data-launcher="false" | Hides the round button. Open the chat from your own button with Casdesk.open() |
data-mode="page" | Fills the whole page with the chat, instead of a button and a panel |
JavaScript API
Once the script has loaded, the page can call:
| Call | Does |
|---|---|
Casdesk.open() | Opens the chat |
Casdesk.close() | Closes it |
Casdesk.toggle() | Opens or closes it |
Casdesk.setUser({ id, username, name, email, hash }) | Tells the chat who the signed-in user is, see Signed-in visitors |
The widget fires a casdesk:ready event on window when it is ready. For example, a "Chat with us" button of your own:
<script src="https://desk.casdoor.com/widget.js" data-site="example-com" data-launcher="false" async></script>
<button onclick="window.Casdesk && Casdesk.open()">Chat with us</button>With data-launcher="false", Casdesk.open() goes straight to the conversation, since your own button stands for the widget's home.
The chat page
Each site also has a page of its own, to link to from "Contact us", from emails or from an app:
https://desk.casdoor.com/chat/example-comIt shows the same conversation as the widget on your website, in the same browser.
Content Security Policy
If your website sends a Content-Security-Policy header, allow https://desk.casdoor.com in script-src, connect-src and img-src.
Sites
A site is one website that shows the Casdesk chat: its name in the embed code, the domains the widget runs on, who answers it and its settings.
Look and texts
Set the Casdesk chat's color, logo, light or dark theme, position, title, greeting, reply time, welcome message, agent avatar, language and when to ask for the visitor's email.