1
Good afternoon, people, I’m racking my brain here and I couldn’t find a solution. What I need is this.
If a user accesses a url for ex: www.site.com.br/produto
it should be redirected to another page with a login type ex: www.site.com/login
.
If he logs in he wanted the user to be redirected to the previous page, but adding the following parameter at the end of the URL: ?id=CS
The example I gave would then be: www.site.com.br/produto?id=CS
window.location.href = '/?id=CS';
The above code redirects only to the home page, but wanted it to go back to the previous page that he tried to access.
I’ll take a test and I’ll be right back
– Frederico Moreira
@Fredericomoreira blz
– Leonardo Bonetti
@Did Fredericomoreira work out? if yes mark as correct by kindness
– Leonardo Bonetti
It worked. Thank you!
– Frederico Moreira
Leonardo, could you help me with something else. I have the following problem. If the previous url already has ? id=Cs on it, the system is adc another at the end, making the page not open. How could I check the URL before adding? For example, if there is "? id=CS" I would not add anything to the url or add &id=Cs
– Frederico Moreira
@Fredericomoreira ready, using the
indexOf
passing the string you want to find inside the url, it returns the index, if it is -1 it means it didn’t find it, take a look at the edition– Leonardo Bonetti
I understood, but in case I need to know if it exists in the URL of Document.referrer which is the previous url we are at the moment. Just change the window.location.href?
– Frederico Moreira
And there is another problem, imagine that the previous url has another parameter, e.g.: site.com.br? test=1 actually I would need to know if there is a parameter in pq url if there exists I would have to adc was &id=CS or ? id=CS
– Frederico Moreira