Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added docs on how to dynamically load script tag #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@ Once you're satisfied with the settings, click on the **SAVE** button. A script
</div>


### Dynamically adding the script tag

In case you have a dynamically loading web application (e.g. Angular based), just adding the `<script>` tag typically won't work. HTML5 does not allow `script` tags to be dynamically added using the `innerHTML` attribute. Details can be found in the [HTML5 spec](https://www.w3.org/TR/2008/WD-html5-20080610/dom.html#innerhtml0).

The solution is to add the `script` tag dynamically by creating a new script element and append it to the target element.

```shell
var newScript = document.createElement("script");
newScript.setAttribute("channelId","<MY_CHANNEL_ID>");
newScript.setAttribute("token","<MY_TOKEN>");
newScript.setAttribute("id","cai-webchat");
newScript.src = "https://cdn.cai.tools.sap/webchat/webchat.js";
document.body.appendChild(newScript);
```

### Self-hosted webchat

If you want to customize your webchat even more, you can opt for a self-hosted installatiton. Just fork this project to get started!
Expand Down