How to create a Dynamic GO BACK button on a 404 Error Page
Make money for being or staying online/internet.

You will get a $50 starting gift when you join using this code: Exode4LKrbujm1z and link:: GET THE OFFER NOW!!

Hey friend,welcome back to the site.If its your first time then trust me you have just joined to right crew in web development.

In this simple article, I will take you step by step on how to create a dynamic Back button on the 404 Error Page(Page Not Found) in case you have one. When i say "a dynamic back button" i mean being able to track the previous page the user came from.

If you don't have one(404 Error Page) then first read this article on how to setup or create your custom 404 Error Page for your website.

READ: How to Create a Custom 404 Error Page in HTML.

The logic is very simple, We will be using the window.history object together with the go() method.

The History object provides an interface for manipulating the browser session history (pages visited in the tab or frame that the current page is loaded in).

For security reasons the History object doesn't allow the non-privileged code to access the URLs of other pages in the session history, but it does allow it to navigate the session history.

The go() method of the History object loads a URL from the history list.



Remember the parameter can either be a number which goes to the last session URL within the specific position or a string. The string must be a partial or full URL, and the function will go to the first URL that matches the string.

Watch the video to see how it's done.

This is the first method on how you can implement a dynamic go back button on your 404 error page.Here we use the inline javascript statement inside the hyper reference attribute (href="").


<a href="javascript:history.go(-1)">go back</a>

Incase you don't want conjest you anchor tag with alot of inline statements,what you need to do is to assign an id to the anchor tag element as shown below.


<a id="backBtn">go back</a>

After assigning an id (forexample:: backBtn) to the element, Then go to the bottom of your page right before the closing body tag (</body>) and create your own custom script tags and insert the code shown below in the middle of the tags.


//select the element and add a click event

//Function to run when a user clicks the go back button
function goBack(){

Note: This method will not work if the previous page does not exist in the history list.

Alright friend,thats it for this article but remember they are very many ways to go around this incase this method didn't help you.

Save up to 80% with this Domain & Shared Hosting package deal! 80% OFF - GET OFFER NOW

Related Post(s)

» How to detect whether the browser is online or offline using Javascript

» How to create Custom Social Media Share Buttons Using JavaScript

» Learn how to animate the value of the placeholder attribute with JAVASCRIPT

» Create a simple currency converter - HTML/Javascript

» How to create a Dynamic GO BACK button on a 404 Error Page

collections_bookmark Category :: Javascript
date_range Published :: 5 years ago At: 02:04 PM
event_note Detailed Date :: Jun 12th, 2019
person Writer :: Code
1 year ago

How to force the browser to cache a page?

There are several ways to force a web browser to cache an HTML page:

1 year ago

How can i cache pages using php?

You can use the output buffering functions in PHP to cache pages. Output buffering allows you to store the output of a PHP script in a buffer, which you can then manipulate before sending it to the client.

1 year ago

PHP explained in a few lines

PHP is a popular programming language that is widely used for web development. It stands for "PHP: Hypertext Preprocessor" and is a server-side scripting language. This means that it is executed on the server, rather than in the user's web browser.

1 year ago

HTML explained in a few lines

HTML, or Hypertext Markup Language, is the standard markup language for creating web pages and web applications. It is used to structure and organize content on the web, and to create the basic structure and layout of a webpage.

1 year ago

CSS explained in a few lines

CSS, or Cascading Style Sheets, is a stylesheet language used for describing the look and formatting of a document written in HTML. CSS is used to control the presentation of multiple web pages at once, making it a crucial tool for web developers and designers.

2 years ago

A JavaScript library for formatting and manipulating numbers - Numeral.js

Check out this lightweight JavaScript library used for formatting and manipulating numbers.

3 years ago

All Countries Drop Down List | HTML Select Country Name

This simple country dropdown list is freely available for you to copy and use in your project forms.

3 years ago

HTML Entities Code Alphabet Discovery Using JavaScript

In this post I will show how writing just a few lines in JavaScript will allow you to render, browse and discover the alphabetical letters using a set of HTML entity codes.