如何将参数传递给Script标签? [英] How to pass parameters to a Script tag?

查看:1138
本文介绍了如何将参数传递给Script标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了教程: http://drnicwilliams.com/2006/11/21/diy-widgets/ 博士的XSS Widgets NIC。

I read the tutorial: http://drnicwilliams.com/2006/11/21/diy-widgets/ for XSS Widgets by Dr. Nic.

我正在寻找一种将参数传递给脚本标签的方法。例如,要进行以下工作:

I'm looking for a way to pass parameters to the script tag. For example, to make the following work:

<script src="http://path/to/widget.js?param_a=1&param_b=3">

有没有办法做到这一点?

Is there a way to do this?

更新:两个有趣的链接:

UPDATE: Two interesting links:

  • How to embed Javascript widget that depends on jQuery into an unknown environment (Stackoverflow discussion)
  • An article on passing parameters to a script tag

推荐答案

知道了。有点破解,但它的效果非常好:

Got it. Kind of a hack, but it works pretty nice:

var params = document.body.getElementsByTagName('script');
query = params[0].classList;
var param_a = query[0];
var param_b = query[1];
var param_c = query[2];

我将脚本标记中的params作为类传递:

I pass the params in the script tag as classes:

<script src="http://path.to/widget.js" class="2 5 4"></script>

这篇文章有很多帮助。

这篇关于如何将参数传递给Script标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆