Return to Snippet

Revision: 6808
at June 16, 2008 12:24 by micmath


Initial Code
function getPathToSelf() {
	var myName = /(^|[\/\\])path\.js(\?|$)/;
	var scripts = document.getElementsByTagName("script");
	for (var i = 0; i < scripts.length; i++) {
		var src;
		if (src = scripts[i].getAttribute("src")) {
			if (src.match(myName)) {
				return src;
			}
		}
	}
}
alert(getPathToSelf());

Initial URL

                                

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

Initial Title
Get url to external script

Initial Tags

                                

Initial Language
JavaScript