!!![AngularJS] [JavaScript] 実行しているパスを取得 ローカルで実行している場合、 function get_location_path() { var dir = location.href; var pos = dir.indexOf('://'); if (pos > 0) { dir = dir.substr(pos + 4); } var pos2 = dir.lastIndexOf('/'); if (pos2 >= 0) { dir = dir.substr(0, pos2); } return dir; } のようにすると、location.hrefで「file://C:/users/hoehoe/html/test/index.html」のような、JavaScriptを実行している際のパスを取得できます。 上記のget_location_path関数では、先頭の「file://」と末尾の「/index.html」をカットして、「C:/users/hoehoe/html/test」というローカルでの絶対パスを取得することになります。 dir = get_location_path(); のようにすると、(ローカルでの実行時は)絶対パスが返ります。 Web上で実行している場合は、location.hrefで「http://www.hoehoe.com/test/index.html」みたいなURLが取得されます。 ---- {{lastmodified}}