Home   Developing   -   Bootstrap   Q&A   Issues   References   Notes   History   Attic  

Goto previous pageGoto parent pageGoto next page
Page 4 of 9

Blocco Notes Logo

Daftari Home - Developing

Questions and Answers (Q&A)


How to get the path of the current script?

This is a re-occurring question during JavaScript livetime. We have implemented this perhaps at several locations. One of them is:

   // ...
   // ...
. In his blog article Javascript: Path to the current script 2011, Ben Carpenter explains a technique to deduce the script path from the script tag in the HTML code (# 20110820.2021).
   // Algorithm to read the script path from the html script tag
   // by Ben Carpenter # 20110123.1154
   var scriptPath = function ()
   {
      var scripts = document.getElementsByTagName('SCRIPT');
      var path = '';
      if(scripts && scripts.length>0) {
         for(var i in scripts) {
            if(scripts[i].src && scripts[i].src.match(/script\.js$/)) {
                path = scripts[i].src.replace(/(.*)script\.js$/, '$1');
            }
         }
      }
      return path;
   };
jsi-boostrap.js
. This page adds to the discussion: http://stackoverflow.com/questions/2161159/get-script-path (# 20110820.2022) (jsi-boostrap.js)
. This page adds more to the discussion: https://github.com/madrobby/scriptaculous/blob/master/src/scriptaculous.js (# 20110820.2023) (jsi-boostrap.js)

.


[Next question]

[Next answer]

   //
. .

. . .