javascriptgoogle-chromelocal-files

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


I'm building an application in an environment where I'm restricted to using the local file system and a browser (i.e. running a server isn't an option). I have a generic 'go back' link on numerous pages that mainly just calls history.back(). It looks something like the following:

function goBack(evt) {
    // Check to see if override is needed here

    // If no override needed, call history.back()
    history.back();
}

$('#my-back-button').click(goBack);

This code works fine in Firefox and IE6 (don't ask), but fails in Chrome. Any suggestions as to why and/or possible workarounds?

I've also tried history.go(-1); which does not work either.


Solution

  • 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;
    }