문제

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 (i.e., 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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top