window点location(仅介绍window点location对象,不介绍属性,因标题不能含有非法字符,.用点来代替)

1.前言:

这个是我做CG-CTF-Web-单身二十年时遇到的,这里就该题简单总结一下

2.window.location介绍

获取当前页面地址(URL)并把浏览器重定向到新页面
搭建环境测试
test.html代码:

<html>
<head>
<script type="text/javascript">
function wanzhengurl()
{
alert(window.location)
}
function chongdingxiangurl()
{
window.location="/no_key_is_here_forever.php"
}
</script>
</head>

<body>
<input type="button" onclick="wanzhengurl()" value="Get URL">
<input type="button" onclick="chongdingxiangurl()" value="Change URL">
</body>

</html>

(1)获取到该页面完整url:
在这里插入图片描述
(2)进行重定向URL(no_key_is_here_forever.php不在根目录下,在根目录的下一级window.location_test目录下,因此报错)
在这里插入图片描述
总结:由上面测试可以看出,window.location="/no_key_is_here_forever.php",是将获取到的完整的URL后,仅保留根目录,也就是将no_key_is_here_forever.php替换根目录后面的所有目录,即最后重定向的URL为http://127.0.0.1:8008/no_key_is_here_forever.php


3.做CTF题时遇到的代码

<script>window.location="./no_key_is_here_forever.php"; </script>

上面的js代码也是将页面重定向到no_key_is_here_forever.php,只不过原先的/变成了./,这又是什么意思呢
于是我又在本地搭了个环境用做测试,环境搭建:
在这里插入图片描述
index.html:

<html>
    <head>
        <meta http-equiv="content-type" content="text/html;charset=utf-8">
    </head>
    <body>
        <a href="./search_key.php">重定向URL</a>
    </body>
</html>

search_key.php:

<script>window.location="./no_key_is_here_forever.php"; </script>
key is : nctf{yougotit_script_now}

no_key_is_here_forever.php:

<?php
echo "这里真的没有KEY,土土哥哥说的,土土哥哥从来不坑人,PS土土是闰土,不是谭神";
?>

上面index.html获取当前页面完整的URL也是http://127.0.0.1:8008/window.location_test/search_key.php,之后进行重定向,多了个./,我们来看看是个什么情况:
在这里插入图片描述
哎?它这里怎么没有用no_key_is_here_forever.php替代除根目录外的所有目录,而是只替换了当前URL的最后一个目录,最后重定向的URL为http://127.0.0.1:8008/window.location_test/no_key_is_here_forever.php,原来这就是./的作用!!

注:如果是window.location="no_key_is_here_forever.php",没有/呢?经测试,没有/./效果一样,都是只替换完整URL的最后一个目录。


4.总结

window.location="/no_key_is_here_forever.php"是用no_key_is_here_forever.php替换完整路径除根目录外的所有目录

window.location="./no_key_is_here_forever.php"和window.location="no_key_is_here_forever.php"是用no_key_is_here_forever.php替换完整路径的最后一个目录


注:
想要了解它的属性的可以看以下几个网址:
http://www.w3school.com.cn/js/js_window_location.asp
http://www.w3school.com.cn/jsref/dom_obj_location.asp

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

1stPeak

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值