我尝试制作像谷歌分析这样的服务,用户将脚本放在他们的html中。
问题是当我的服务器为脚本提供服务时,它必须进行一些操作并根据请求域发送不同的脚本。
抱歉我的英文
非常感谢你的帮助
答案 0 :(得分:1)
我,找到了解决方案,非常简单
服务器文件夹中的:
Router.route("metric", {
where: "server",
path: "/dinamic.js",
action: function () {
//here all your acctions
ponse.writeHead(200, {
"Content-Type": "application/javascript"
});
this.response.end(
"console.log('in this line your dynamic " + "js" + " code')"
);
}
});
答案 1 :(得分:-1)
You can produce JS dynamically from PHP
Plz take reference from this example
script.php
<?php
$id=$_REQUEST["id"];
$name=$_REQUEST["name"];
if($id>10)
?>
console.log("Hello <?php echo $name;?> your ID is <?php echo $id;?>");
<?php
else
?>
alert("Hello <?php echo $name;?> your ID is <?php echo $id;?>");
In your html code (under a server side script file) you just need to dynamically change the src attrbute of the script tag
<script src="script.php?name=<?php echo $your_name;?>&id=<?php echo $your_id;?>"></script>