Extract external query string / javascript binding value: file.js # foo = bar

http://mycloud.net/js/file.js#foo=bar

I am trying to load a cross-domain javascript file and want to pass a variable along the query string. I saw the above method "#", but I'm not sure how to extract the value "foo" from file.js. Any tips on how to handle this without the help of server side help?

Thank.

+3
source share
2 answers

Well, there really is a way to get the current one script, for example:

// external script
(function () {
  var scripts = document.getElementsByTagName('script'),
      currentScript = scripts[scripts.length - 1],
      scriptUrl = currentScript;

  alert("scriptUrl: " + scriptUrl);
})();

, script script DOM (scripts[scripts.length - 1]).

scriptUrl, GET.

, script .

+3

script - - script scr.

URL- , .

+1

Source: https://habr.com/ru/post/1741962/


All Articles