Naor
Naor

Reputation: 24083

javascript file location

I want to unite the javascript plugin file an its style css file under one folder. I also want to add th reference to the css file inside the javascript file itself. What is the best way to do so?

Right now I can't get the js file location.

Upvotes: 0

Views: 297

Answers (1)

Eli Grey
Eli Grey

Reputation: 35860

If you don't care about supporting IE:

var getErrorLocation = function (error) {
    var loc, replacer = function (stack, matchedLoc) {
        loc = matchedLoc;
    };

    if ("fileName" in error) {
        loc = error.fileName;
    } else if ("stacktrace" in error) { // Opera
        error.stacktrace.replace(/Line \d+ of .+ script (.*)/gm, replacer);
    } else if ("stack" in error) { // WebKit
        error.stack.replace(/at (.*)/gm, replacer);
        loc = loc.replace(/:\d+:\d+$/, ""); // remove line number
    }
    return loc;
};

try {
    0();
} catch (e) {
    var scriptURI = getErrorLocation(e);
}

Otherwise, it's impossible.

Upvotes: 3

Related Questions