For browsers that support document.currentScript, use document.currentScript
和document.currentScript.src
The lower version of ie traverses the script tag to determine whether the value of readyState is "interactive",
The above two can be perfectly obtained
If neither is supported, the path is obtained through stack, but the element cannot be obtained perfectly, and the value of src is judged by traversing the script tag,
The problem is that multiple scripts with the same path are loaded at the same time and cannot be judged correctly, but this is rare.
If stack does not support it, you can only get the last element,
Some test results:
For e.fileName of firefox and e.sourceURL of safari, the obtained address is the address of the error report, which can only be used directly. For example, a.js calls the getCurrentPath function in b.js, and the obtained address is b.js. So it doesn't work.
The address obtained by the onerror event of IE, ie8 is the js address, and ie7 and ie6 are the addresses of html, so onerror cannot be used.