0

I want to add "/finished" on my URL when click on button withou reloading the page or if it's not possible the "/", only "-finished".

My URL is: www.myname.com/firstparemeter/secondparameter**/finished**

So, the script must add after the last "/" or only add a "-finished" on the last word of the URL.

<script>
$(document).ready(function () {

    $('#btnclick').click(function () {
         window.location.hash = '/finished';
    });

});
</script>

The HTML:

<input type="submit" value="SUBSCRIBE" class="btn-submit" id="btnclick" onclick="IsEmpty();" />

Can you guys help me? I'm begineer

Victor
  • 53
  • 1
  • 6

2 Answers2

1
history.pushState({}, "", window.location.hash + "/finished")

It could be window.location.href as well

cuzox
  • 794
  • 7
  • 15
  • Its working with the window.location.href, but when already has one "/" it's adding one more "//". It's there a way to verify if already has one "/"? – Victor Nov 08 '18 at 18:37
  • Maybe i can add something like that; clean_url = abc.replace(/([^:]\/)\/+/g, "$1"); – Victor Nov 08 '18 at 18:45
  • you can check if window.location.href.slice(-1) == '/' – cuzox Nov 08 '18 at 19:13
0
history.pushState({}, '', '/finished')
Unmitigated
  • 76,500
  • 11
  • 62
  • 80
Natan Farkash
  • 256
  • 3
  • 4