Why not login to Qiita and try out its useful features?

We'll deliver articles that match you.

You can read useful information later.

6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Javascript]URL情報(フルパス, ファイル名以外)を表示

Last updated at Posted at 2015-10-13

URL表示テスト

sample.html
<HTML>
<HEAD>
<TITLE></TITLE>
<SCRIPT language="JavaScript">
<!--
// 警告ウィンドウを表示する
function show() {
  var fullpath = location.pathname;
  var url      = location.href.split(/#/)[0]; // hash に / を含むことがある場合を考慮
  var url_path = url.substring(0, url.lastIndexOf("/"));

  window.alert("[location.pathname:]->\n"+fullpath+"\n\n"+
               "[location.href:]->\n"+url+"\n\n"+
               "[location.href(except filename):]->\n"+url_path);
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<A href="#" onClick="show()">パスを表示する</A>
</BODY>
</HTML>
6
4
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?