The Little Guy Posted January 26, 2011 Share Posted January 26, 2011 How can I get the current location of the js file? if I do this: alert(location.href); I get http://somesite.com/folder/file.html What I want is: http://somesite.com/javascript/script.js how can I get that? Link to comment https://forums.phpfreaks.com/topic/225766-current-location-of-a-javascript-file/ Share on other sites More sharing options...
.josh Posted January 26, 2011 Share Posted January 26, 2011 You have to do something like this: page where you are including script <script id='something' type='text/javascript' src='script.js'></script> inside your script alert(document.getElementById('something').src); Or retrieve the script src through other means (like get element by tag name or if you use jquery get it that way or w/e)...the point is that you have to get it by looking for the src of the script include. Link to comment https://forums.phpfreaks.com/topic/225766-current-location-of-a-javascript-file/#findComment-1165597 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.