title: How to get current url along with query string in jQuery
body: <p>I want current url path along with its query string.</p>
  
  <p>I have tried below but not getting desired output.</p>
  
  <pre><code>var pathname = window.location.pathname; // Returns path only
  var url = window.location.href;
  </code></pre>
  
  <p>Suppose my url is <a href="http://localhost:1111/Contact/Index?text=aa" rel="nofollow noreferrer">http://localhost:1111/Contact/Index?text=aa</a>.</p>
  
  <p><strong>Note</strong>  : query string is optional here if there is no query string then it should provide pathname only.</p>
  
  <p>I want <strong>/Contact/Index?text=aa</strong>, TIA.</p>