Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
141
rated 0 times [  147] [ 6]  / answers: 1 / hits: 53518  / 15 Years ago, thu, april 2, 2009, 12:00:00

I'm pretty sure the answer is no, but thought I'd ask anyway.



If my site references a scripted named whatever.js, is it possible to get whatever.js from within that script? Like:



var scriptName = ???

if (typeof jQuery !== function) {
throw new Error(
jQuery's script needs to be loaded before +
scriptName + . Check the <script> tag order.);
}


Probably more trouble than it's worth for dependency checking, but what the hell.


More From » html

 Answers
63
var scripts = document.getElementsByTagName('script');
var lastScript = scripts[scripts.length-1];
var scriptName = lastScript.src;
alert("loading: " + scriptName);

Tested in: FF 3.0.8, Chrome 1.0.154.53, IE6




See also: How may I reference the script tag that loaded the currently-executing script?


[#99756] Sunday, March 29, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ravenl

Total Points: 338
Total Questions: 107
Total Answers: 112

Location: Belize
Member since Mon, Jun 20, 2022
2 Years ago
ravenl questions
Thu, Feb 18, 21, 00:00, 3 Years ago
Tue, Jan 12, 21, 00:00, 3 Years ago
Tue, Mar 17, 20, 00:00, 4 Years ago
;