---
title: "ajax后退解决方案（一）"
author: "zhouyrt"
date: "2011-11-11T13:52:07Z"
tags: []
categories: ["Web前端"]
slug: "ajax"
draft: false
lastmod: "2011-11-11T17:06:16Z"
id: 1253704
url: "https://snandy.iteye.com/blog/1253704"
---

**一、使用iframe，通过document.write产生历史**

 

```
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"/>
	<title>0</title>
</head>
<body>
	<input type="button" value="加1" onclick="add()" />
	<div id="info" style="border:red 1px solid;width:200px;padding:10px;margin:5px;">0</div>
</body>
</html>
<script src="history-0.1.js"></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>
```

 

 

点击按钮后更新页面DOM（模拟ajax提交），会发现浏览器后退按钮可用了。点击后退，可返回到前一个状态。

这种方式缺点是只支持IE和Firefox。

 

[history-0.1.js](http://files.cnblogs.com/snandy/history-0.1.js)