Each AJAX operation appends a number to the IFRAME.SRC question mark to record history. Click the Back button, iframe in the OnLoad event to obtain the URL of the IFRAME, according to the number after the question mark to fetch records.
<! DOCTYPE html>
<meta charset= "Utf-8"/>
<title>0</title>
<body>
<input type= "button" value= "plus 1" onclick= "Add ()"/>
<div id= "Info" style= "border:red 1px solid;width:200px;padding:10px;margin:5px;" >0</div>
</body>
<script >
/**
* History.js v0.2
* Copyright (c) Snandy
*
* 1 using IFRAME to create history by modifying IFRAME.SRC
* 2 Ie6/7/8/9/10/firefox/safari/chrome/opera are supported
*
*/
History = function () {
Var
Iframe
Store history
List = [],
History index
index = 0,
Pushing;
iframe = document.createelement (' iframe ');
Iframe.style.display = ' None ';
Iframe.onload = function () {
if (pushing) return;
var url= this.contentWindow.location.href;
if (Url.indexof ('? ') >-1) {
var idx = url.substr (Url.indexof ('? ') +1);
Get (IDX);
}
}
Document.body.appendChild (IFRAME);
function push (data) {
if (typeof data!== ' object ') return;
if (typeof Data.param = = Undefined | | | typeof data.func!== ' function ') return;
List[index] = data;
Updateiframe ();
Pushing = true;
index++;
settimeout (function () {
Pushing = false;
}, 100);
}
function Updateiframe () {
IFRAME.SRC = ' blank.html ' + index;
}
Function Get (idx) {
var item, param, func, scope
if (idx!= index) {
item = List[idx];
if (item) {
param = Item.param;
func = Item.func;
scope = Item.scope;
func.call (scope, param);
}
}
}
return {
Push:push
};
}();
</script>
<script>
var info = document.getElementById (' info ');
var i = 1;
function Add () {
info.innerhtml = i;
Document.title = i;
var data = {
PARAM:I,
Func:func
};
History.push (data);
i++;
}
History.push ({param:0, func:func});
function func (i) {
info.innerhtml = i;
Document.title = i;
}
</script>
<! DOCTYPE html>
<title>blank.html</title>
<body>
</body>