将其放在需要知道其自身URL的js文件中。
完全合格 (例如
http://www.example.com/js/main.js):
var scriptSource = (function(scripts) { var scripts = document.getElementsByTagName('script'), script = scripts[scripts.length - 1]; if (script.getAttribute.length !== undefined) { return script.src } return script.getAttribute('src', -1)}());
或 如其在来源中所示 (例如
/js/main.js):
var scriptSource = (function() { var scripts = document.getElementsByTagName('script'), script = scripts[scripts.length - 1]; if (script.getAttribute.length !== undefined) { return script.getAttribute('src') } return script.getAttribute('src', 2)}());
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)