javascript - 如何将参数传递给脚本标签?

标签 javascript parameters widget xss script-tag

我阅读了教程 DIY widgets - How to embed your site on another site Dr. Nic 的 XSS Widgets。

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

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

有办法吗?


两个有趣的链接:

最佳答案

我为回答一个 super 老问题而道歉,但在花了一个小时与上述解决方案搏斗之后,我选择了更简单的东西。

<script src=".." one="1" two="2"></script>

在上面的脚本中:

document.currentScript.getAttribute('one'); // 1
document.currentScript.getAttribute('two'); // 2

比 jQuery 或 URL 解析容易得多。

您可能需要来自 @Yared Rodriguez's answerdocument.currentScript 的 polyfill对于 IE:

document.currentScript = document.currentScript || (function() {
  var scripts = document.getElementsByTagName('script');
  return scripts[scripts.length - 1];
})();

关于javascript - 如何将参数传递给脚本标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5292372/

相关文章:

javascript - 如何在 React JS 的组件中通过 props 显示信息

javascript - 使按钮关闭整个 session 的 div

javascript - 获取 dataTables 和 twitter bootstrap 工作时出现问题

java - 这个方法返回什么?

flutter - Flutter-小部件的状态未更改

c++ - 添加小部件不起作用

javascript - iDangerous Swiper初始滑动设置

c# - 如何在 C# 中将特定参数标记为过时/弃用?

swift - 将类作为参数传递给函数以便快速进行比较?

python - 文本小部件填充一半屏幕