abcnews/scriptroot

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

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

scriptroot

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.

Usage

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.

Huge caveat

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.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.