Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
165
rated 0 times [  168] [ 3]  / answers: 1 / hits: 137072  / 15 Years ago, thu, august 27, 2009, 12:00:00

I am using the following for getting the JavaScript caller function name:



var callerFunc = arguments.callee.caller.toString();
callerFuncName = (callerFunc.substring(callerFunc.indexOf(function) + 8, callerFunc.indexOf(()) || anoynmous)


Is there a way to discover the line number from which the method was called?



Also, is there a way to get the name of the JavaScript file the method was called from? Or the source URL?


More From » javascript

 Answers
10

This works for me in chrome/QtWebView



function getErrorObject(){
try { throw Error('') } catch(err) { return err; }
}

var err = getErrorObject();
var caller_line = err.stack.split(n)[4];
var index = caller_line.indexOf(at );
var clean = caller_line.slice(index+2, caller_line.length);

[#98822] Saturday, August 22, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
susanap

Total Points: 413
Total Questions: 82
Total Answers: 99

Location: South Georgia
Member since Mon, Oct 19, 2020
4 Years ago
;