Hi, glad to hear that you are using Vaadin 15. For this use case, I think maybe you can create a component wrapper for the chat-widget, sth like
@Tag("div")
@JavaScript("https://chat.movidesk.com/Scripts/chat-widget.min.js")
public class ChatComponent extends Component {
}
Then at the time you need to load the chat-widget, you can simply add the ChatComponent there to the view, so that it will load the JavaScript file and render the component as an empty <div>.
Thank you, I will test …
but I put it in index.html and then via JS I made it visible or not, it also worked … but it ends up being loaded before the moment I really want …
We had a project in Vaadin 8 and rewrote it in the newest Vaadin …
This is a big challenge, but the result is getting really good
Zi Fran:
Thank you, I will test …
but I put it in index.html and then via JS I made it visible or not, it also worked … but it ends up being loaded before the moment I really want …
We had a project in Vaadin 8 and rewrote it in the newest Vaadin …
This is a big challenge, but the result is getting really good
In views created in Java you can use the page.addJavaScript() API in order to add an external script dynamically:
Button button = new Button("Login", e -> {
doLogin();
UI.getCurrent().getPage().addJavaScript("https://chat.movidesk.com/Scripts/chat-widget.min.js");
});
Are you using any TypeScript views in your app? In that case an equivalent would be
Note, that you can set the chat client ID also dynamically if you do not want to show it for non-logged-in users.
In Java (note the extra LoadMode.LAZY to start loading the script after executing the JS snippet):