Loading the Widget with RequireJS
If you use RequireJS on your website, you also need to load our Widget via RequireJS. To do so, just take a look at our sample snippet below and paste in the code of the Widget you would like to load. Find the unique Widget code in your Widget’s settings under Install > JavaScript Widget code.
To use your own on-ready callback function, pass the relevant object to the "load" method ready: function
.
💡
Our Widget uses a single global object to handle JSONP callbacks. Please make sure not to overwrite the userlike-object in the global scope.
javascript
require.config({ paths: { 'userlike-loader': '{{javascript_loader_url}}' } }); require(['userlike-loader'], function(userlike) { userlike.load({ ready: function() { console.log('Widget is ready.'); }, onError: function(e) { console.error('Error while loading the Widget.', e); }, }); });
After loading the Widget with a module loader you are still able to reference the Widget in the global scope by calling the "window.userlike" object.
💡
To avoid CSS conflicts with the chat client, we advise you not to use iframe { !important } in your CSS. Better be more specific and exclude the Userlike chat client by using iframe:not(.userlike) { !important }.
Share