how to embed the whole html file into JS

Home / javascript / how to embed the whole html file into JS

Question:
I am trying to implement an online chat functionality on 3 of my websites, but I dont want to copy paste my whole code on every website. I want to create something like tawk.to has. They just have a

Basically in my page's tag I will include this JS.



Here is what tawk.to does:

You just paste this code in your page and it displays chat box along with the functionality


Answer:
Yes you can do this by below approach.
....

Create a JS file
IN that file write a logic to create chat button.
That file can have click events of that button which is added at run time VIA ajax.
You can then include this file in all the HTML pages where you need chat functionality.
Make sure you load this file at the end of body tag.
Read more

Leave a Reply

Your email address will not be published. Required fields are marked *