/ Published in: JavaScript

This could be included inside the external script itself, and compared to window.location if the returned URL were relative.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function getPathToSelf() { var myName = /(^|[\/\\])path\.js(\?|$)/; var scripts = document.getElementsByTagName("script"); for (var i = 0; i < scripts.length; i++) { var src; if (src = scripts[i].getAttribute("src")) { if (src.match(myName)) { return src; } } } } alert(getPathToSelf());
Comments
