R
R
Rokis2015-10-26 21:50:52
JavaScript
Rokis, 2015-10-26 21:50:52

how to add number to number in page url in javascript?

I get the url of the current page and want to add a number to it like 2. My url is like mysite/site/29448 .
document.location.href + 2
This code changes my url to mysite /site/29448/2/ and also adds /2/ on the next execution .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Deodatuss, 2015-10-26
@Rokis

var newHref = document.location.href.split("/");
newHref[newHref.length-1]=+newHref[newHref.length-1]+2;
newHref=newHref.join('/');
document.location.href=newHref;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question