I Want JavaScript To Redirect - Not Working

I want to redirect my website to https://uprightcode.com/comming-soon
my code so far in js is

location.replace("https://uprightcode.com/comming-soon")

When I save and deploy successfully and the indicator is published in Netlify I try going on my website again and it has shows the homepage and I want a few minutes and go grab a snack, I come back and it is still not redirected. What is the problem?

I have also tired

window.location = "https://uprightcode.com/comming-soon";

Video to see https://vimeo.com/559126337

Hi @Codeman, I don’t see an immediate issue with your code… do you have a link to the page to come?

BTW note that the equivalent to using the assignment operator would be, well, location.assign() – with location.replace() the current page will not be saved in the browser history, which may or may not be desired.

1 Like

what do you mean by

A link to the page containing your code, i.e. that should redirect to the “coming soon” page.

1 Like

I have 9 js files total of 906kb each with a ton of javascript I am not sure If I want to.

should be window.location.replace

It is probably a problem with other files of code the redirect works perfectly on codepen as you can see here.

https://codepen.io/Javscript/pen/wvJmVBP

EDIT (or an extra thing)
My Code Up There: RIP:2021-2021 LAst Words - “I am Not responsive”

The reason I’m asking is that we we need to inspect the code in its context – there’s nothing wrong with it per se:

Edit:

Yup, that’s exactly what I was getting at.

1 Like

also… why would your page have lots of javascript files and a lot of javascript, if all you want the page to do is redirect?
Your entire page should be like…

<html>
<body>
<script>
window.location.replace("go here");
</script>
</body>
</html>

?

3 Likes

the other ones are for stuff. Duh

Then configure a proper server-side redirect… I have no experience with netlify myself but it seems to be easy enough:

SUCCESS

I did this

it worked

image

1 Like

Hmm, that is pretty awkward though. I do not see anything wrong with your code. Have you fixed it already?! What was wrong?

The post above yours answers these question!