㈠ 如何在HTML文件中通过javascript获得当前网页的绝对路径和相对路径
绝对路径:
<!DOCTYPEhtml>
<html>
<body>
<script>
document.write(location.href);//输出当前页面完整URL
</script>
</body>
</html>
相对路回径:
<!DOCTYPEhtml>
<html>
<body>
<script>
document.write(location.pathname);//返回当前URL的路答径名
</script>
</body>
</html>
使用javascript来获取当前url网址非常有用。下面以例子讲解:
输入的网址是(没有框架):http://localhost:81/Test/1.htm?Did=123
<br>以下为输出:
<br>
<SCRIPT>
//获取Url传过来的值
function Request(name)
{
new RegExp("(^|&)"+name+"=([^&]*)").exec(window.location.search.substr(1));
return RegExp.$2
}
thisURL = document.URL; // http://localhost:81/Test/1.htm?Did=123
thisHREF = document.location.href; // http://localhost:81/Test/1.htm?Did=123
thisSLoc = self.location.href; // http://localhost:81/Test/1.htm?Did=123
thisDLoc = document.location; // http://localhost:81/Test/1.htm?Did=123
thisTLoc = top.location.href; // http://localhost:81/Test/1.htm?Did=123
thisPLoc = parent.document.location;// http://localhost:81/Test/1.htm?Did=123
thisTHost = top.location.hostname; // localhost
thisHost = location.hostname; // localhost
thisU1 = window.location.protocol; // http:
thisU2 = window.location.host; // localhost:81
thisU3 = window.location.pathname; // /Test/1.htm
document.writeln( thisURL + "<br />");
document.writeln( thisHREF + "<br />");
document.writeln( thisSLoc + "<br />");
document.writeln( thisDLoc + "<br />");
document.writeln( thisTLoc + "<br />");
document.writeln( thisPLoc + "<br />");
document.writeln( thisTHost + "<br />");
document.writeln( thisHost + "<br />");
document.writeln( thisU1 + "<br />");
document.writeln( thisU2 + "<br />");
document.writeln( thisU3 + "<br />");
document.writeln( "Did="+Request("Did") );// Did=123
</SCRIPT>
㈢ js获取文件路径怎么写
<script>
$("input[name=fileString]").change(function(){
//varnames=[];
for(vari=0;i<$(this).get(0).files.length;++i){
//names.push($(this).get(0).files[i].name);
//console.log($(this).get(0).files[i].mozFullPath);
//方式一:
varfilePath=$(this).val();
console.log(filePath);
//方式二:
alert($('input[type=file]').val());
}
//console.log(names);
//方式三:
alert($("input[name=fileString]").val());
})
</script>
注意:以上方式取到的都是文件的伪路径,由于浏览器的安全策略,Chrome浏览器及内核的浏览器是不可能获取文件在本地的真实路径的。IE浏览器可以通过设置安全级别,能获取到真实路径。
㈣ js如何获取当前页面所在的路径
可以使用window对象的location对象的里的href来获取当前页面的URL地址。
工具原料:编辑器、浏览器
1、Location 对象包含有关当前 URL 的信息,Location 对象是 Window 对象的一个部分,可通过 window.location 属性来访问,代码示例如下:
<html>
<head><scripttype="text/javascript">
<script>
alert(window.location.href);
</script>
</script>
</head>
<body>
test
</body>
</html>
2、运行的结果如下图:
㈤ 如何用js获取当前打开的页面的路径
设置或获取对象指定的文件名或路径。
alert(window.location.pathname)
设置或获取整个 URL 为字符串。内
alert(window.location.href);
设置或获取与 URL 关联的端口号容码。
alert(window.location.port)
设置或获取 URL 的协议部分。
alert(window.location.protocol)
设置或获取 href 属性中在井号“#”后面的分段。
alert(window.location.hash)
设置或获取 location 或 URL 的 hostname 和 port 号码。
alert(window.location.host)
设置或获取 href 属性中跟在问号后面的部分。
alert(window.location.search)
㈥ js中如何获取当前浏览器的地址的值
js中通过window.location.href和document.location.href、document.URL获取当前浏览器的地址的值,它们的的区别是:
1、document表示的是一个文档对象专,window表示的是一个窗口对属象,一个窗口下可以有多个文档对象。所以一个窗口下只有一个window.location.href,但是可能有多个document.URL、document.location.href
2、window.location.href和document.location.href可以被赋值,然后跳转到其它页面,document.URL只能读不能写
3、document.location.href和document.location.replace都可以实现从A页面切换到B页面,但他们的区别是:
用document.location.href切换后,可以退回到原页面。
而用document.location.replace切换后,不可以通过“后退”退回到原页面。
㈦ js 如何获取当前网页的本地路径
varlcal=location.href;
lcal=substring(0,lcal.lastIndexOf(""));
㈧ js 得到保存路径
classloader
㈨ 如何利用JS获取到的完整路径
js,可以使用如下获取
window.location.href
一般来说,路径都使用jsp的内置对象获取,比较基础,网上一搜一大堆
㈩ js 获取上级目录路径
//假设你的路径为str
str="a.com/aaa/bbb/1.html"
str=str.replace(/\/[^\/]+\/[^\/]+$/,"/");