Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incrementally increasing number in URL - JavaScript

I have a URL like http://blog.com/post/1 and I need a function which updates the number at the end of it, for pagination.

So far I have:

window.location(document.URL++);
like image 410
sanjaypoyzer Avatar asked Feb 18 '26 19:02

sanjaypoyzer


1 Answers

var url  = window.location.href.split('/'),
    page = parseInt(url.pop(), 10);

// to go to next page, increment page number and join with URL

window.location.href = url.join('/') +'/'+ (++page);

FIDDLE

like image 75
adeneo Avatar answered Feb 20 '26 07:02

adeneo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!