Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can javascript file get its own name?

I am trying to build some sort of logger functionality in javascript. Is there any API for a script to get its own filename?

like image 710
Manohar Avatar asked Dec 08 '09 09:12

Manohar


1 Answers

This should work: (new Error).fileName

Or you can try this:

var filepath;
(function(){ 
    var scripts = document.getElementsByTagName('script'); 
    filepath = scripts[ scripts.length-1 ].src; 
}());

The second option gives you the path of your script file.

like image 57
pawel Avatar answered Nov 11 '22 22:11

pawel