有两种方法可以做到这一点。一种是使用 HTML5 History API,将是这样的代码:
var i = 0;
setInterval(function() {
history.pushState(null, document.title, 'example.com/' + i++);
}, 1000);
However, this will push it to the browser history and not all browsers support it. If I remember correctly there's a way to push it to url without pushing it to history, but read a bit about it to see if you can do it.
Or you can use hash codes in case you don't mind a little #
over there, but it will probably annoy the visitor as it might bump the page to top every second, if you don't mind then this is your code :
var i = 0;
var url= window.location.href;
setInterval(function() {
window.location.href = url+"#"+i++;
}, 1000);
However this sounds like a bad idea anyway, so reconsider using it. I'm pretty sure what you're trying to achive can be done in a cleaner way.