---
title: "禁止页面缓存与离开页面确认"
author: "jil5"
date: "2012-11-29T20:17:58Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2012-12-06T15:25:11Z"
id: 1738529
url: "https://jil5.iteye.com/blog/1738529"
---

禁止页面缓存

 

```
response.addHeader("Cache-Control", "no-store, must-revalidate"); 
response.addHeader("Expires", "Thu, 01 Jan 1970 00:00:01 GMT");
response.setDateHeader ("Expires", 0); 
```

```
window.history.forward(1); 
location.replace("");
```

   

 

 

离开提示

 

var timeout=true;//设置变量 在某些时刻不提醒

```
//--------------离开提示---------------------	
	window.onbeforeunload = function(e){
		if(!timeout){
			window.event.returnValue='您确认离开考试页面吗？';
			 if (!window.event.reason) 
	            {
	              window.event.cancelBubble = true;
	            } 
	            else
	            {
	            	return;
	            }
			}
		}
```