手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >Document.location.href和.replace的区别示例介绍
Document.location.href和.replace的区别示例介绍
摘要:document.location.href和document.location.replace都可以实现从A页面切换到B页面,但他们的区别...

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页面时,

内存中保留的是A和B

>>>当一个文档被location.replace()替换后,它就会从当前的历史对象中移除了

【Document.location.href和.replace的区别示例介绍】相关文章:

新页面打开实际尺寸的图片

零基础学Swift:Core Foundation框架

javascript带回调函数的异步脚本载入方法实例分析

浅析Javascript匿名函数与自执行函数

jQuery实现在列表的首行添加数据

编写高质量JavaScript代码的基本要点

教学演示-UBB,剪贴板,textRange及其他

解析Node.js基于模块和包的代码部署方式

document 和 document.all 分别什么时候用

JavaScript实现DIV层拖动及动态增加新层的方法

精品推荐
分类导航