简体   繁体   中英

Getting full URL with jQuery including parameters after question mark?

I am trying to use jQuery to get the current full URL of a page. The URL of a page looks like this:

http://myurl.com/ebook?page=43

If I use window.location.pathname it only returns everything before the ? so I would just get

http://myurl.com/ebook

How can I get the entire URL?

You have:

window.location.href

and also:

document.URL

If you want to return the whole URL, you need to use window.location.href .

Using window.location.pathname only returns the path portion of the URL which excludes the query parameters and fragment (ie, starting at the / following the host but only up to a ? or # ).

Example:

> window.location.pathname
"/ebook"
> window.location.href
"http://example.com/ebook?page=43"

Also, see the documentation for window.location for more available properties.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM