AJ.
AJ.

Reputation: 11240

HTML button that reloads refering page

I have created a HTML error page which has a button with text Try Again. When the user clicks this button I would like to reload the refering page.

Looking on Google there are a few ways to do this, but I am unsure of which is the best way that will work in the majority of browsers.

Anyone help?

Thanks,

AJ

Upvotes: 0

Views: 849

Answers (4)

Joel
Joel

Reputation: 19358

You could use the history api:

<a href="javascript-required" onclick="history.go(-1);return false;">Try again</a>

Upvotes: 0

Siedrix
Siedrix

Reputation: 641

Most browsers have a window location object that has a reload function

window.location.reload()

So you button will look like

<input type="button" value="Reload Page" onClick="window.location.reload()">

Upvotes: 0

Jason Spick
Jason Spick

Reputation: 6088

try:

<input type="button" onclick="window.location.reload();" value="Try again" />

Upvotes: 0

Pointy
Pointy

Reputation: 413717

Your code that handled the original HTTP request resulting in the error knows that URL, so it should simply create a link back on the error page; just a simple link, or whatever else that's appropriate for your overall site design.

Do not rely on the HTTP "REFERER" value.

Upvotes: 2

Related Questions