Skip to content

Instantly share code, notes, and snippets.

@danbrianwhite
Last active December 16, 2015 03:59
Show Gist options
  • Save danbrianwhite/cf498723b834ebd154c2 to your computer and use it in GitHub Desktop.
Save danbrianwhite/cf498723b834ebd154c2 to your computer and use it in GitHub Desktop.
filePath
var filePath = function()
{
//grab the path of this js file (must include name of file)
var _scripts = document.getElementsByTagName("script");
var _pattern = /^(.*?)\/js\/filePath.js/i;
var _path;
for (var i = _scripts.length - 1; i >= 0; i--)
{
var checkPath = _pattern.exec(_scripts[i].src);
if (checkPath != null)
{
_path = checkPath[1];
i = -1;
}
};
var _originRegExp = new RegExp(window.location.protocol+"//"+window.location.host, "g");
if(_path.match(_originRegExp) == null)
{
_path = window.location.protocol+"//"+window.location.host + _path;
}
return _path;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment