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

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

问题描述

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

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

示例网址:

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

推荐答案

获取路径可以使用:

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天全站免登陆