首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

学习document.location.href跟document.location.replace 区别

2012-10-28 
学习document.location.href和document.location.replace 区别document.location.href和document.location

学习document.location.href和document.location.replace 区别
document.location.href和document.location.replace都可以实现从A页面切换到B页面,但他们的区别是:

用document.location.href切换后,可以退回到原页面。

而用document.location.replace切换后,不可以通过“后退”退回到原页面。

关于document.location.href或其他可回退的切换方式,我还发现一个细节,

用个例子来说明:

假设有A.htm B.htm C.htm三个页面

A.htm里有这样一句:document.location.href="b.htm";

b.htm里有这样一句:document.location.href="c.htm";

注意两个都是可回退的切换。


1:当从A切换到B再切换到C时,实际内存中保留了三个页面:A、B、C

2:回退到B时,C页面被清出内存!

3:再次回退,到A页面时,B页面也被清出内存!

4:再次向前(不是用切换而是用向前)转到B页面时,

热点排行