1
I have a function called redirectToNextPage that does the following: Takes the value of the URL from the previous page and, after three seconds, redirects to the next page, using an IF for each URL, with one exception, because the home page can start without the final parameter that I configured through queryParams.
I’m taking the URL of the inner page inside the class builder:
this.history = document.referrer
/// O document.referrer existe porque ele está redirecionando para essa página através de um link.
That is the function :
redirectToNextPage() {
if (this.history === 'http://127.0.0.1:5500/quiz.html' || this.history === 'https://127.0.0.1:5500/quiz.html?quiz=1') {
setTimeout(() => {
window.location.href = 'http://127.0.0.1:5500/quiz.html?quiz=2'
}, 3000);
}
if (this.history === 'http://127.0.0.1:5500/quiz.html?quiz=2') {
setTimeout(() => {
window.location.href = 'http://127.0.0.1:5500/quiz.html?quiz=3'
}, 3000);
}
if (this.history === 'http://127.0.0.1:5500/quiz.html?quiz=3') {
setTimeout(() => {
window.location.href = 'http://127.0.0.1:5500/quiz.html?quiz=4'
}, 3000);
}
Well, the function goes like this until the 'quiz.html.? quiz=10'. However, I decided not to put the whole function here so as not to become giant so you don’t get bored.
In short. What I want is to change the end of the URL, adding an extra number at its end, each time it is redirected to the specific page.
What I tried to:
let historyArray = this.history.split('')
let takeLastNumber = historyArray.pop()
console.log(historyArray)
console.log(historyArray.join())
for (var i = 1; i <= 10; i++) {
console.log('http://127.0.0.1:5500/quiz.html?quiz=' + i)
}
I tried to transform the string into an array, take out the last element of it - which is the number - and then bring it into an array of a single index, which would be the integer link minus the last number. However, I’m not getting it. Because it’s returning like this on the console and I don’t understand why:
h,t,t,p,:,/,/,1,2,7,. ,0,. ,0,. ,1,:,5,5,0,0,/,r,e,d,i,r,e,c,t,. ,h,t,m,l,? ,r,e,d,i,r,e,c,t,=,1
Well, I’d like to know how I can resolve this in a simpler way. I am still beginner in programming and want to avoid these bad practices.
It might be interesting to check for the case
NaN
also.– Luiz Felipe
Thank you very much for your reply! :)
– PiviaN
@Luizfelipe well noted, I added the reply thank you
– Ricardo Pontual