Can I get the history.back() function to work in Chrome when using the file:// protocol? Can I get the history.back() function to work in Chrome when using the file:// protocol? google-chrome google-chrome

Can I get the history.back() function to work in Chrome when using the file:// protocol?


For some reason in chrome, you have to add return false after calling history.go(-1)

Change your function to:

function goBack(evt) {// Check to see if override is needed here// If no override needed, call history.back()history.go(-1);return false;}


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>Untitled Document</title></head><body><script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script><script>$(document).ready(function () {    function goBack(evt) {    // Check to see if override is needed here    // If no override needed, call history.back()    history.back();    $('#my-back-button').forwardEvent('click');}$('#my-back-button').click(goBack);/*** chrome workaround for triggering click events* @param {event} event  event* @return {undefined}   Returns undefined*/    $.fn.forwardEvent = function(event) {        this.each(function() {            if (this.dispatchEvent) {                if (event.originalEvent) {                    event = event.originalEvent                }                try {                    this.dispatchEvent(event);                } catch(error) {                    $(this).trigger(event);                }            }            else {                $(this).trigger(event);            }        });        return this;    };});</script><input type="button" value="<<<<" id="my-back-button"></body></html>


var referrer = document.referrer;window.location.replace(referrer);

Use this it will work