0

i have a anchor like:

<div class="fc-content cursor event_border' onclick="test(edate)"></div>

calling function is given below:

<script type="text/javascript">
   function test(id,evntDate)
   {
      var str = evntDate.toString();
      str = str.replace(/\//g,'');
      var pathname = window.location.pathname; // Returns path only
      var url      = window.location.href; 
      var querystring ='?date='+str;
      window.location.replace(url+querystring);

   }
</script>

after this i am getting the url like:

localhost/abc/cde?date=2018-07-26

but when i click again on this url its returning me the query string like:

http://localhost/proflyt/dashboard?date=2018-07-26?date=2018-07-24

its not removing the first query string and returning me the url like so because of this i am not able to use my code further can anyone please help me related this ?? i am new in jquery i am stuck here not able to solve and not getting any kind of response please help me related this ..

1
  • 1
    window.location.href will include the query string. You can build the new URL from the component parts of the location like protocol, host, etc. Commented Jul 24, 2018 at 12:35

1 Answer 1

1

You need just use origin and pathname instead href.

<script type="text/javascript">
   function test(id,evntDate)
   {
      var str = evntDate.toString();
      str = str.replace(/\//g,'');
      var pathname = window.location.pathname;
      var ogigin      = window.location.ogigin; 
      var querystring ='?date='+str;
      var url = ogigin + pathname + querystring
      window.location.replace(url);

   }
</script>

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

Comments

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.