javascript - how to embed the whole html file into JS -
i trying implement online chat functionality on 3 of websites, dont want copy paste whole code on every website. want create tawk.to
has. have <script>
tag , paste tiny code on our page , whole functionality rendered through js.
right have in html file, logic in js in same html file.
something this?
<script src="path-to-my-file.js"></script>
basically in page's tag include js.
<!doctype html> <body> <script src="loads-html-from-other-place"></script> </body>
here tawk.to does:
<!--start of tawk.to script--> <script type="text/javascript"> var tawk_api=tawk_api||{}, tawk_loadstart=new date(); (function(){ var s1=document.createelement("script"),s0=document.getelementsbytagname("script")[0]; s1.async=true; s1.src='https://embed.tawk.to/12341/default'; s1.charset='utf-8'; s1.setattribute('crossorigin','*'); s0.parentnode.insertbefore(s1,s0); })(); </script> <!--end of tawk.to script-->
you paste code in page , displays chat box along functionality
yes can below approach.
.... </body> <script src="path-to-my-file.js"></script>
create js file
in file write logic create chat button. file can have click events of button added @ run time via ajax. can include file in html pages need chat functionality. make sure load file @ end of body tag.
Comments
Post a Comment