Get parameters of .js file

孤者浪人 提交于 2019-12-01 20:57:31

Take a look a scriptaculous' approach:

var js = /scriptaculous\.js(\?.*)?$/;
$$('head script[src]').findAll(function(s) {
  return s.src.match(js);
}).each(function(s) {
  var path = s.src.replace(js, ''),
  includes = s.src.match(/\?.*load=([a-z,]*)/);
  (includes ? includes[1] : 'builder,effects,dragdrop,controls,slider,sound').split(',').each(
   function(include) { Scriptaculous.require(path+include+'.js') });
});

I think it runs through all script elements and finds the reference to itself, and then parses that URL.

If you want to do it reliably, then you need to provide different JS for each URL. You could generate it with a server side script.

If you want to do it in pure JS, then you can getElementsByTagName('script') and assume that last script is the one that matched (it might not be, e.g. if script elements are being added using DOM after the page has loaded).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!