使用jQuery获取当前URL? [英] Get current URL with jQuery?

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

问题描述

我正在使用jQuery。如何获取当前URL的路径并将其分配给变量?

I am using jQuery. How do I get the path of the current URL and assign it to a variable?

示例URL:

http://localhost/menuname.de?foo=bar&number=0


推荐答案

要获取路径,您可以使用:

To get the path, you can use:

var pathname = window.location.pathname; // Returns path only (/path/example.html)
var url      = window.location.href;     // Returns full URL (https://example.com/path/example.html)
var origin   = window.location.origin;   // Returns base URL (https://example.com)

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

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