最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Show placeholder page when browser receives 302 request - Stack Overflow

programmeradmin3浏览0评论

When a browser is receiving redirect request from server, for a fraction of second, browser shows an error page that says "Page not found", and then redirects to appropriate url.

I am looking for solution where browser, instead of displaying "Page not found" page, shows a dummy page.

I assume this is what payment gateways are doing by displaying a page that says "Do not press back/refresh button".

When a browser is receiving redirect request from server, for a fraction of second, browser shows an error page that says "Page not found", and then redirects to appropriate url.

I am looking for solution where browser, instead of displaying "Page not found" page, shows a dummy page.

I assume this is what payment gateways are doing by displaying a page that says "Do not press back/refresh button".

Share Improve this question asked Aug 23, 2017 at 10:15 Aki008Aki008 4032 gold badges6 silver badges19 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 4 +25

I believe your initial premise that when a browser receives a 302 response code it shows an error, might be incorrect.

You can see redirects happening in many websites where all the browser does is just change the address in the address bar and load the eventual page, without displaying anything in the mean time.

Moreover, the 302 HTTP status code is not intended to have a body part, and if it has one it is usually ignored. And so, I can think of only two things that may be happening:

  1. You're using some browser that has a different behavior when accepting a 302 code (older?).
  2. The server isn't sending a 302, and in fact is sending back a page with redirection code in it.

A good way to check this depends on which browser you're using, but most modern browsers have a 'developer' pane where you can see the outgoing requests and ining responses and their headers and status codes. You can then verify what is actually happening.

If the case is the former, then I'm afraid there's probably not much you can do about it without altering the browser itself. If it is the latter, then assuming the server code is under your control, you can change whatever content is returned.

I assume this is what payment gateways are doing by displaying a page that says "Do not press back/refresh button"

To achieve this you can use meta tag to refresh / redirect. The following snippet is taken from this SO post

<meta http-equiv="refresh" content="3;url=http://www.google./" />

You can add a Custom error page

To map 302 to a static HTML file, you need to create an html file called 302.html under resources/public/error, your folder structure should look like:

src/
 +- main/
     +- java/
     |   
     +- resources/
         +- public/
             +- error/
                 +- 302.html

If you are using Spring (as the tag suggests) you can have a class to handle the redirection, which redirects you immediately to the page you desire.

There are multiple different ways to handle redirection, here you have a good guide: http://www.baeldung./spring-redirect-and-forward

发布评论

评论列表(0)

  1. 暂无评论