0

I want current url path along with its query string.

I have tried below but not getting desired output.

var pathname = window.location.pathname; // Returns path only
var url = window.location.href;

Suppose my url is http://localhost:1111/Contact/Index?text=aa.

Note : query string is optional here if there is no query string then it should provide pathname only.

I want /Contact/Index?text=aa, TIA.

MD. Khairul Basar
  • 4,976
  • 14
  • 41
  • 59

2 Answers2

0

In jQuery you can do

$(location).attr('href')

The location object also contains properties, like host, hash, protocol, and pathname.

Red
  • 6,599
  • 9
  • 43
  • 85
-2

This window.location.pathname will give you the path or the url.

SilverSurfer
  • 4,281
  • 6
  • 24
  • 50