Is there such a thing as a "frontend redirect" and if so how to block such redirects from JavaScript?

I know that JavaScript can’t prevent or can’t be used to block backend redirects done by a webserver such as Apache or Nginx.

But is there such a thing as a “frontend redirect” and if so how to block such redirects from JavaScript?

I would imagine a “frontend redirect” as something done with XHR/FetchAPI/AJAX, tools which I am not familiar with, but just know that they often used as alternatives to backend server requests and backend server responses.

Well there are many forms of redirects at various levels/times.

  1. You have DNS redirects which the browser asks for example1.com and it is told that example1.com should go to example2.com but don’t tell the browser anything different.

  2. You have web server redirects… these are your typical 301/302 redirects where the web server for example1.com tells the browser “Hey, I can’t handle this request. Go to example2.com for this.” in which case the browser automatically then sends another request to example2.com.

  3. You have meta tags where the web server for example1.com sends back an HTML document, but it contains a tag that says “Hey, browser, after a specific amount of time, go ahead and go to this other URL.”

  4. Then you have what you are calling front end redirects where some JavaScript is served by the web server on example1.com and in response to something the user does (clicks a button, or a specific time out etc.) the javascript loads another URL into the windows.location.href or windows.location.replace() (depending on if you want to keep the history).

Now keep in mind when these are run. Obviously the DNS/Server ones are out of your reach to do anything. The Javascript one is up to you and your browser on how you process it and when. I am not sure you can necessarily “block” it, but if you are the one writing the Javascript sent by the server, you can control when that redirect is done and in response to the user.

If you can elaborate on what you mean by “block” it and give us a basic scenario, we can probably give you more information on what you can do.

I’ll gladly elaborate :slight_smile:

Please go to this webpage:

https://search.google.com/search-console/about

As far as I have understood form @m_hutley there is a redirection there.

Can this very redirection be prevented with JavaScript?

I am not sure I see any kind of redirect there. The server comes back with a 200 status code and the page is showing exactly the link you are showing there. Am I suppose to click something to get the redirect to happen?

So the way the problem was stated originally was that if a user goes to search.google.com he wanted a script to bounce to google.com instead. If you go to just search.google.com, you get 301’d. However, if you go to the longer link that has now been shared, you dont.

Specificity. It is often required.

To answer the question, i’ve never heard of a ‘frontend redirect’, but if i had to imagine such a concept, i’d imagine it like a default pageloader in a routed system; find route /search-console/about; if not existant, insert index.html.

It’s not advised (because the HTTP standard provides a proper way to redirect a client, the aforementioned 301/302 system), but that’s what i’d imagine it to be.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.