I currently have a JavaScript component within the home component that utilizes an external script. My goal is to remove the external script when navigating to another page, without refreshing the page.
<script>
function initFreshChat() {
window.fcWidget.init({
token: "***",
host: "https://wchat.freshchat.com"
});
}
function initialize(i,t){var e;i.getElementById(t)?initFreshChat():((e=i.createElement("script")).id=t,e.async=!0,e.src="https://wchat.freshchat.com/js/widget.js",e.onload=initFreshChat,i.head.appendChild(e))}function initiateCall(){initialize(document,"freshchat-js-sdk")}window.addEventListener?window.addEventListener("load",initiateCall,!1):window.attachEvent("load",initiateCall,!1);
</script>
The link to the external script:
This setup allows me to maintain the Freshchat window on one specific page. While I can achieve this with conditions, it requires a page refresh. As the pages do not refresh, I am seeking a solution to dynamically remove the external script when navigating to other pages and reinstate it upon returning to this particular page.