Manohar Manohar - 6 months ago 41
Javascript Question

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?

hsz hsz

I see two ways:

  • put into every JS file a variable var filename = 'script.js';
  • get the filename using <script> tag name

JS can not get filename like bash/perl/c scripts.