0

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

4
  • 1
    please show us what you have tried. google "jquery get substring", read and experiment. Commented Jun 15, 2016 at 16:41
  • 1
    Nothing in core jQuery is designed for URL parsing. Commented Jun 15, 2016 at 16:41
  • See over there on the right where it says Related? Have a look at a few of those Commented Jun 15, 2016 at 16:41
  • ManoDestra: Thanks. Commented Jun 15, 2016 at 17:40

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

Esko: Thanks a lot. It is helpful answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.