Posted By

micmath on 06/16/08


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

korzhik


Get url to external script


 / Published in: JavaScript
 

This could be included inside the external script itself, and compared to window.location if the returned URL were relative.

  1. function getPathToSelf() {
  2. var myName = /(^|[\/\\])path\.js(\?|$)/;
  3. var scripts = document.getElementsByTagName("script");
  4. for (var i = 0; i < scripts.length; i++) {
  5. var src;
  6. if (src = scripts[i].getAttribute("src")) {
  7. if (src.match(myName)) {
  8. return src;
  9. }
  10. }
  11. }
  12. }
  13. alert(getPathToSelf());

Report this snippet  

You need to login to post a comment.