HTTP Status Codes: 302, 303, and 307

Browsers implement both 302 and 303 to mean to go to the new URL including the get query string. 307 instructs the browser to repost any post data to the new URL including the get query string. Here is what I found on Windows.

IE properly and silently reposts as you would expect.

Firefox 2/3

Firefox asks the user to click OK to execute the repost or CANCEL to do nothing. Doing nothing might mean that the page loads up blank, which is kind of silly.

Opera 9.25

Opera is similar to Firefox but provides a third option. Opera prompts with YES to repost, NO to use get only, and CANCEL to do nothing.

Safari 3

Safari treats a 307 the same as a 303 and gives no option to repost. Technical tests from the phaq blog.

My solution

My solution was to use 307 for IE and use HTML and JavaScript for the other browsers. I made a form full of hidden fields for each posted value and then submitted the form through JavaScript. To users, the redirect looks as you would expect.

The trick was that I could not use document.forms[0].submit() because sometimes one of the hidden elements is named submit. So I had to use an additional button that was positioned with top: -100px; in the style attribute.

For those with JavaScript disabled, I used noscript tags to enclose a notice that the page was moved and a button to go to the new location.

Demos + Source

Partial solution which always does a 307 but falls back to JavaScript when user cancels (Does not work in Safari 3, does not work when user chooses NO in Opera 9.25.)

Final solution which does a 307 for IE but uses JavaScript for other browsers

Thoughts

I was surprised to see different behavior in every browser. I don’t see the advantage of the prompt other than a possible security exploit. This is an instance where IE got it exactly to spec!