导航:首页 > 编程语言 > js获取自身路径

js获取自身路径

发布时间:2021-03-23 17:41:54

㈠ 如何在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>

js取得本地路径的代码

使用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(/\/[^\/]+\/[^\/]+$/,"/");

阅读全文

与js获取自身路径相关的资料

热点内容
超凡蜘蛛侠2苹果版免费 浏览:110
苹果6s放大器怎么设置密码 浏览:626
windows7怎么没有无线网络 浏览:917
5s苹果手机录像只有沙沙响的声音 浏览:879
多张图纸怎样打印到一个pdf文件里 浏览:347
安装cad2020出现无法定位inf文件 浏览:728
百度竞价数据如何分析 浏览:965
ps文件发送第三方打印 浏览:547
linux命令界面显示文件名 浏览:930
超级录屏视频在文件夹里不能播放 浏览:549
最简单的编程软件有哪些 浏览:14
博客签到系统如何设计数据库 浏览:639
论文怎么设置目录word 浏览:609
广电网络dlna是什么意思 浏览:12
js变量加下划线 浏览:18
app开发工作是吃青春饭吗 浏览:117
苹果手机国家查询 浏览:765
苹果6照片删了怎么找回 浏览:399
文件夹控制面板 浏览:536
人工神经网络人脸识别 浏览:531

友情链接