Reinitialize zendesk script with iframe



已于 2024年4月03日 发布

I use the standard zendesk script when initializing my application. Everything works fine. But I have several different chat rooms and at a certain action for example the user has logged into my application, I should change {my_key} and a new zendesk widget will load. But this is not happening. When I change the conditions, {my_key} is inserted correctly, but the widget itself does not change. 
I tried to delete the script and div element in which the Iframe zendesk. Tried to disable cookies for zendesk, with popposchuyu window.zE('messenger:set', 'cookies', false); and then re-enable. 
In general, tell me how to dynamically change the key in script tag src, load a new chat?

<!-- Start of priokunden Zendesk Widget script -->
<script id="ze-snippet" src="https://static.zdassets.com/ekr/snippet.js?key={my_key}"> </script>
<!-- End of priokunden Zendesk Widget ->


0

1

1 条评论

The following did the trick for me.

 

This is NOT production ready code. It is for demo purposes only. Please make it look awesome and test carefully before using in production.

 

(function(){

	// remove old widget
	zE('messenger', 'hide'); zE('messenger', 'logoutUser');
	document.getElementById('ze-snippet').remove();
	window.zE = undefined;
	window.zEmbed = undefined;
	window.zEACLoaded = undefined;
	window.zESettings = undefined;


	// add new widget
	var my_awesome_script = document.createElement('script');
	my_awesome_script.id = "ze-snippet";
	my_awesome_script.setAttribute('src','https://static.zdassets.com/ekr/snippet.js?key=XXXXX');
	document.head.appendChild(my_awesome_script);

})();

0


登录以发表评论。

找不到所需的内容?

新建帖子