1

I've created a custom 505 error page for my site (as the default one that shows up is pretty nasty on the eyes). Everything is as it should be but I'm unsure about my usage of JS, I am trying to link the 'Retry' button in this image:

Image 001

to a javascript/jQuery action that will reload the page that was initially requested.

i.e If the user requested example.com/thispage and they were shown the custom '500 Internal Server Error' page, when they click on 'Retry' the reload request would be for the example.com/thispage page.

The javascript I'm using is:

<a href="javascript:window.location.href=window.location.href"><img src="IMAGE SOURCE HERE"></a>

In test mode (i.e loaded from my local documents folder) this just refreshes the custom error page.

So I guess I have 2 questions:

1) Will this reload the requested URL or the custom 505 error file;

2) If it will reload the file how can I use JS to reload the initial page request?

Note: I have included jQuery:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

in the head of the document.

  • Firstly, use `window.location.reload()` to reload the page on button click. To answer #1, it will load whatever the current URL is, so exactly what gets reloaded will depend on how you redirect to the 505 error page. – Rory McCrossan Jun 23 '17 at 14:26
  • @RoryMcCrossan Hi, thanks! Without wanting to sound like an amateur I'm using Wordpress as the site's CMS, I'm not sure what the default behaviour is here, all the posts I've read are about fixing these errors instead of trying to spoof one so that I can test how things load :/ do you know what the correct method would be for this setup? –  Jun 23 '17 at 14:31
  • Well, I'm not sure how Wordpress does this internally, but you need to ensure that you do a 307 redirect to the error page so that the original URL is retained so that any requests to reload the page attempt to access the original resource, not the error. – Rory McCrossan Jun 23 '17 at 14:35
  • @RoryMcCrossan Okay that's great, thank you for clarifying this for me I'll see if I can work it out and post back a full working solution. :) I appreciate your assistance! –  Jun 23 '17 at 14:37

1 Answers1

0

you can try

window.location.href=document.referrer

but i'm ot sure it will work in every situation