使用JavaScript获取URL的一部分 [英] Getting parts of a URL with JavaScript

查看:104
本文介绍了使用JavaScript获取URL的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在 www.google.com/folder/folder/archive.php 并使用 window.location 确定。我实际上想要定位 /archive.php ,而不是别的。

I'm currently on www.google.com/folder/folder/archive.php and using window.location to determine that. I actually want to target /archive.php, and nothing else.

有什么东西可以实现吗?

Is there something that could achieve that?

window.location.host = "www.google.com"

window.location.pathname = "folder/folder/archive.php"

???? = "/archive.php


推荐答案

试试这个:)

console.log(window.location.href.split('/').pop())

这篇关于使用JavaScript获取URL的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆