---
title: "window.location.assign(url)和replace(url)区别"
author: "wtsoftware"
date: "2009-07-21T10:45:05Z"
tags: []
slug: "window-location-assign-url-replace-url"
draft: false
lastmod: "2009-07-21T10:45:05Z"
id: 429866
url: "https://wtsoftware.iteye.com/blog/429866"
---

window.location.assign(url) ： **加载** **URL** **指定的新的** **HTML** **文档。** **就相当于一个链接，跳转到指定的url，当前页面会转为新页面内容，可以点击后退返回上一个页面。**

window.location.replace(url) ： **通过加载** **URL** **指定的文档来替换当前文档** **，这个方法是替换当前窗口页面，前后两个页面共用一个**

**窗口，所以是没有后退返回上一页的**

转自:http://hi.baidu.com/zp8126/blog/item/91c3d70389a8b3713912bbe4.html