我正试图在我的3个网站上实现在线聊天功能,但我不想复制粘贴我的整个代码在每个网站上。我想要创建一些像tawk.to一样的东西。它们只有一个<script>标记,我们在页面上粘贴一小段代码,整个功能就通过JS呈现出来。
现在我把它放在一个HTML文件中,我的逻辑在JS中的同一个HTML文件中。
像这样的东西?
<script src="path-to-my-file.js"></script>基本上,在我的页面标记中,我将包括这个JS。
<!DOCTYPE HTML>
<body>
<script src="loads-html-from-other-place"></script>
</body>下面是tawk.to的功能:
<!--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-->您只需将此代码粘贴到您的页面中,它将显示聊天框和功能
发布于 2017-08-18 23:58:21
是的,你可以通过下面的方法做到这一点。
....
</body>
<script src="path-to-my-file.js"></script>创建JS文件
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.https://stackoverflow.com/questions/45760124
复制相似问题