Kaizur Kaizur - 5 months ago 10
Javascript Question

Get a part from URL with jQuery

How could I get the part before "?" of a URL with jQuery?

For example, I have following URL:

http://example/group/abc/?author=gfg&city=gfg

I want to get this:

http://example/group/abc/




If the URL is this:

http://example/group/abc/xyz?author=gfg&city=gfg

I want to get this URL:

http://example/group/abc/xyz

Answer

No jQuery Necessary.
window.location.href.split('?')[0]

Comments