Name: scriptroot
Owner: ABC News
Description: Grab the path from which a script has been loaded
Created: 2014-11-21 01:06:49.0
Updated: 2014-11-21 01:23:06.0
Pushed: 2014-11-21 01:19:38.0
Homepage: null
Size: 100
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Get a fully qualified URL for the folder a given script is in.
The basic purpose of this script is to facilitate the loading of assets relative to the script rather than relative to the document.
This is designed to be included in scripts using Browserify, but could reasonably be used as a global if you know your environment and understand how it works.
equire script root.
nsure this isn't run inside a domready listener. It must be executed when
he script loads.
scriptroot = require('scriptroot');
og the script root
ole.log(scriptroot());
ipt src="http://example.com/scripts/fancyscript.js"></script>
This will log http://example.com/scripts/
to the console.
This will not work with scripts which have async
or defer
attributes. It
relies on being executed at the point at which the script tag is encountered
during DOM parsing.