Search code examples
javascripthtmlwidgethide

how to add a script to script js


how to add a:

Tawk_API.hideWidget();

//Example

Tawk_API.onLoad = function(){
    Tawk_API.hideWidget();
};

Tawk_API.toggleVisibility();


//Example

Tawk_API.onLoad = function(){
    Tawk_API.toggleVisibility();
};

to

<script type="text/javascript">
  
document.querySelector("#print").addEventListener("click", function() {

	window.print();
});
    </script>

I need hide a chat widget on print page. When i print a page i have a small widget with chat in right bottom corner.


Solution

  • if hiding a widget on the print page means when you click on the print button is only your concern then it will work for you because as I can see in your code you add an event listener to a #print. so I am assuming that works as a print button for you. you can uncomment the code if you required that I marked as a comment. write the following code as you required. Please vote up and accept the answer if it helps you.

    <script type="text/javascript">
      
    document.querySelector("#print").addEventListener("click", function() {
         Tawk_API.hideWidget();
        
    //i dont know why you write below code so i mark it as comment you can uncomment if you need it.
    //Example
    /*
    Tawk_API.onLoad = function(){
        Tawk_API.hideWidget();
    };
    
    Tawk_API.toggleVisibility();
    
    
    //Example
    
    Tawk_API.onLoad = function(){
        Tawk_API.toggleVisibility();
    };*/
    	window.print();
    });
        </script>