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 $5 starting gift when you join using this 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.

syntax
copy

	history.go(number|URL)

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="").

copy

<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.

copy

<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.

copy

//select the element and add a click event
document.getElementById('backBtn').addEventListener('click',goBack);

//Function to run when a user clicks the go back button
function goBack(){
  window.location.href="javascript:history.go(-1)";
}


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)

» JavaScript Quiz App Source Code

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

» Here are some games made with javascript

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

» How to Animate Font Awesome Icons With Javascript

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

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

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


1 year 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.


1 year 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.


1 year ago

YTS YIFY MOVIES API - PROJECT PREVIEW

Download YTS YIFY movies using this simple project I created using their API.


1 year ago

Display Random Advice On Your Website or Web App Using Advice Slip JSON API

Here is a short project to display the use of APIs. I decided to work with an advice API because it seemed like a fun one that I haven't worked on before.


1 year ago

How do I get a YouTube video thumbnail from YouTube using PHP

Have you ever been on youtube and admired a thumbnail of a video?


1 year ago

How to recreate Facebook's console warning

When I was inspecting some code on Facebook. I came across this interesting feature. A simple styled console warning message from Facebook to its dear users(products).


2 years ago

How To Create A Stacked Gallery Using HTML And CSS Source Code

In this post I provide you with the source code for the youtube tutorial I made on how to create a Stacked image gallery Using HTML and CSS.


Subscribe
  • ADVERTISEMENT

YOU MAY LIKE THESE POSTS

share