[英]Define a variable at an js import on index.html
I have a JavaScript
script which a user can import on his website. 我有一个
JavaScript
脚本,用户可以在其网站上导入该脚本。 This script will basicly create an socket connection which transfers small messages which the script will display on the client side. 该脚本从根本上将创建一个套接字连接,该套接字连接将传输小消息,该小消息将显示在客户端。
I will have more than one user on more than one website. 我将在多个网站上拥有多个用户。 So I need an identifier to handle the identification of the website.
因此,我需要一个标识符来处理网站的标识。
I plan to use something like a CDN
to host this script, so the user can just import it within his index.html
. 我计划使用
CDN
类的东西来托管此脚本,因此用户可以将其导入到他的index.html
。 The script does always the same logic but with different Connection Values. 该脚本始终执行相同的逻辑,但具有不同的连接值。 Im pretty sure I dont have to create the same files, with different identifier values, for every websites which will use my script, but so far i have no idea how to tell the script which identifier value it should use.
我很确定我不必为将要使用我的脚本的每个网站创建具有不同标识符值的相同文件,但是到目前为止,我还不知道如何告诉脚本应使用哪个标识符值。
Is there a good way to handle such problems? 有解决这种问题的好方法吗?
将连接ID存储在加载脚本的HTML文档中(例如<script src="http://cdn.example.com/your.js" data-connection-id="74893872"></script>
),拉使用您的JS从DOM中获取。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.