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

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

问题描述

我阅读了教程 DIY 小部件 - 如何将您的网站嵌入另一个网站 尼克博士的 XSS 小部件.

I read the tutorial DIY widgets - How to embed your site on another site 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&amp;param_b=3"></script>

有没有办法做到这一点?

Is there a way to do this?

两个有趣的链接:

  • 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];

我将脚本标签中的参数作为类传递:

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天全站免登陆