JavaScript获取当前文件全路径、当前目录、当前文件名

//获取当前文件全路径

<script language="javascript">

alert(window.location.href);

alert(window.location);

alert(location.href);

alert(parent.location.href);

alert(top.location.href);

alert(document.location.href);

alert(document.URL);

</script>

//获取当前目录方法

<script type="text/javascript">

//方法一

var str = location.href;

var arr = str.split("/");

delete arr[arr.length-1];

var dir = arr.join("/");

alert(dir);

//方法二

alert(location.href.substring(0,location.href.lastIndexOf('/')));

</script>

//获取当前文件名

<script   language=javascript>  

var  filename=location.href;

filename=filename.substr(filename.lastIndexOf('/')+1);  

alert(filename);  

</script>

 

posted @ 2010-07-08 09:42 星火卓越 阅读(...) 评论(...) 编辑 收藏