JQuery back button

I want to create a button that will launch a previously launched function. those. I press button “A” to start function “A”, then press button “B” to start function “B”. I want a button that allows the user to return to function A by pressing the back button.

I thought that a global variable might contain previous statements, but it would not work, since every function executed would overwrite the stored instructions. here is some psuodo code to explain what i mean

var globalvar;
globalvar = functionA;
function B { run globalvar};
+3
source share
2 answers

Use hash hyperlinks and event hashchange. In jQuery:

$(window).on('hashchange',function() {
    var hash = location.hash.substring(1); // strip the leading # symbol
    // now run code based on whatever the value of 'hash' is
});

HTML:

<a href="#hash1">function A</a>
<a href="#hash2">function B</a>

, , "" ( HTML, history.go(-1)), , , .

http://jsfiddle.net/mblase75/hL5FZ/

: , IE7 history.go().

+12

JQuery , :

$(document).ready(function(){
  $('a.back').click(function(){
    parent.history.back();
    return false;
  });
});
+3

All Articles