Ask coding questions

← Back to all posts
How do I make it redirect?
h
awdrgyjil1234 (22)

I am making a repl where it uses javascript to check the page url, and if it is through a proxy it will redirect to the actual page. For example, if the repl is being accessed through https://noderlol.herokuapp.com/proxy/https://welltodojealousdigits.awdrgyjil1234.repl.co/ it would redirect to https://welltodojealousdigits.awdrgyjil1234.repl.co/. But instead it simply keeps reloading the page. Can someone please help me with this?

Comments
hotnewtop
Coder100 (18071)

the reason why is because of this thing right here:

this won't be ever true as the URL is lowercase.

awdrgyjil1234 (22)

@Coder100 so fork it, make the changes it needs, and gimme the link

Coder100 (18071)

a fork isn't really necessary

if (document.URL == 'https://welltodojealousdigits.awdrgyjil1234.repl.co' || 'https://flickeringdaringmenu-212.awdrgyjil1234.repl.co') {
  console.log('good');
  
} 
else {
  window.location.href= 'https://welltodojealousdigits.awdrgyjil1234.repl.co';
}

also
in fact
this script altogether isn't needed, the link will always be correct.
@awdrgyjil1234

Coder100 (18071)

make sure the herokuapp actually works? @awdrgyjil1234

Coder100 (18071)

its pretty clearly the server error and not any code error @awdrgyjil1234

InvisibleOne (2934)

try location.href = 'url' and make sure the URL contains https:// or http://

awdrgyjil1234 (22)

@InvisibleOne i got it to redirect but all it does is reload the page forever

InvisibleOne (2934)

That's because your javascript file has an error. Change it to:

if  (window.location.href = 'url') {
  console.log('good');
} else {
  window.location.href= 'url';
}

@awdrgyjil1234

awdrgyjil1234 (22)

@InvisibleOne all it does is keep reloading the page

InvisibleOne (2934)

woops, change line 1 to :

if (document.URL == 'https://WelltodoJealousDigits.awdrgyjil1234.repl.co') {

@awdrgyjil1234

awdrgyjil1234 (22)

@awdrgyjil1234 still keeps reloading the page

awdrgyjil1234 (22)

@InvisibleOne still reloads the page forever

InvisibleOne (2934)

I think that it is a problem in WeilltodoJeal0usDigits as to why it keeps reloading itself. Can I see the code? @awdrgyjil1234

awdrgyjil1234 (22)

@InvisibleOne here is index.html:

<!DOCTYPE html><html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>repl.it</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <script src="script.js"></script> </body> </html>
InvisibleOne (2934)

I mean in the script in the repl that you are forwarding it too. @awdrgyjil1234