2
I would like to get a url that is found right after red=
and redirect to it in case it is blank not redirect. I used window.location.replace("")
only to test the code.
Example of where I’m going with this: red=http://www.google.com/
The code has the function of replacing the content within an element, and redirect the page in a few seconds.
window.onload = function substituir() {
var url = new URL(window.location);
var sub = url.searchParams.get("sub");
var red = url.searchParams.get("red");
setTimeout(redirecionar, 5000);
if(sub == 1) {
document.getElementById("subst").innerHTML = "<p>Alguma coisa</p>"
}
function redirecionar() {
if(red == 1) {
window.location.replace("https://www.google.com");
}
}
}
Interesting to send the value in
sub
for the element, but the redirect problem if the url does not containhttp
, would be in the way offtp
or a magnetic url for example– Mark Vaaz
All right I’ll try to find a solution, thank you.
– Mark Vaaz
It would be more feasible if the redirect worked with any type of url examples:
exemplo.com
www.exemplo.com
http://www.exemplo.com
ftp://
magnet:
– Mark Vaaz
Yes, but how do I know what the link protocol is? If it is http, ftp etc
– Sam
Is it possible to redirect it to anything? example:
red=algumacoisa
without it redirecting as a site page, thus ignoring everything that comes before:http://www.exemplo.com/?sub=1&red=
algumcoisa
– Mark Vaaz
You can redirect it wherever you want, as long as you set it to where. Now, "anything" doesn’t exist. Imagine you arrive in a pharmacy to buy and say: "give me something"... it doesn’t make sense.
– Sam
yes I imagined that it was not possible, just wanted to remove the doubt really, but anyway, it would be interesting if there is
ftp://
magnet:
did not apply the regex/^http:\/\//
– Mark Vaaz
Let’s go continue this discussion in chat.
– Sam