---
title: "JS自动刷新页面一次"
author: "麦田1990"
date: "2013-12-07T13:32:00Z"
tags: []
slug: "js"
draft: false
lastmod: "2013-12-14T11:51:28Z"
id: 1989422
url: "https://alert-null.iteye.com/blog/1989422"
---

```
<script type="text/javascript">
	//刷新页面
	if(location.href.indexOf("refresh=1") === -1) {
	       setTimeout(function() {
		     location = location.href + "?refresh=1"
	       },1)
	}
</script>
```

或者

```
<script type="text/javascript">
	//刷新页面
	function refreshOnce(){
	       if (location.href.indexOf("?xyz=") < 0) {
	             location.href = location.href + "?xyz=" + Math.random();
	        }
	 }
</script>	
		
<body onload="refreshOnce()">
```