Jump to content

404 Redirect


aggixx

Recommended Posts

I want to make a 404 page for my website that redirects the visitor back to their previous page, and gives them a message, telling them a 404 occurred. I want the it to give the effect that if they click on a broken link, a message pops up saying 404, and that they didnt even visit the broken page (or something close to that).I've tried:

 <HEAD>  <script LANGUAGE="JavaScript"> <!-- Begin redirTime = "1"; redirURL = windows.history.back(); alert("Error 404: Page Not Found You have been redirected back to your previous page.") function redirTimer() { self.setTimeout("self.location.href = redirURL;",redirTime); } //  End --> </script>  </head> <BODY onLoad="redirTimer()">

I've also tried:<HEAD>

 <script LANGUAGE="JavaScript"> <!-- Begin alert("Error 404: Page Not FoundYou have been redirected back to your previous page.")window.history.go(-1)}//  End --></script> </head><BODY onLoad="redirTimer()">

Thanks ahead of time.Edit: Oh, I forgot to say how it wasnt working. When you go to a page that doesnt exist, the message pops up, but it doesnt redirect.

Link to comment
Share on other sites

You might want to use a meta refresh instead of a Javascript redirect. There's plenty of information on Google about using that, it's 1 tag that goes in the head. The page content can say that you are being sent back to the last page. You might want to use a server-side language to go back to the right page (the referrer).

Link to comment
Share on other sites

First, take the HTML comments out of the Javascript code and instead of using language="javascript" use type="text/javascript". You can't have linebreaks inside strings in Javascript, you're getting a syntax error. Remove the line break in the call to alert. If you want a line break to appear in the text, use the "\n" sequence.

Link to comment
Share on other sites

Ok, now neither the alert or redirect work, but heres what I have now:

<head><script LANGUAGE="text/javascript">function redirtimer(){alert("Error 404: Page Not Found \n You have been redirected back to your previous page.")window.history.go(-1)}</script></head><BODY onLoad="redirTimer()">

Link to comment
Share on other sites

You have the code like above right, with alert before the redirect? I thought alert boxes were synchronous, so the alert box should be closed before it executes the next line. You can always have it alert on page load and delay the redirect by a couple seconds.

function redirtimer(){alert("Error 404: Page Not Found \n You will be redirected back to your previous page.")setTimeout("window.history.go(-1)", 3000);}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...