注意,不是当前页面的地址window.location.href
,而是脚本资源的地址,比如我在html里引用了这个页面
<script src="http://example.com/script.js?param=123456"></script>
那么如何在这个js里面获取本身的实际调用地址http://example.com/script.js?param=123456
呢?
解决方案
可以这样获取,因为当前执行的script肯定是当前已加载的所有script中的最后一个。
var scripts=document.getElementsByTagName('script');var lastUrl=scripts[scripts.length-1].src;