`
zjf201172653
  • 浏览: 45421 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

Document.location.href和.replace的区别

阅读更多
转自 http://www.cnblogs.com/GT_Andy/archive/2007/10/31/1922138.html

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()替换后,它就会从当前的历史对象中移除了

分享到:
评论

相关推荐

    刷新页面的几种方法小结(JS,ASP.NET)

    Javascript刷新页面的几种方法: 1. history.go(0) 2.... document.URL=location.href 自动刷新页面的方法: 1.页面自动刷新:把如下代码加入<head>区域中 <meta http-equiv=”refresh”

    jsp目录动态菜单

    jsp目录动态菜单代码片段 function ShowMenu(obj,n){ var Nav = obj.parentNode; if(!Nav.id){ var BName = Nav.getElementsByTagName("ul");... window.location.href="http://www.baidu.com"; } //--> </script>

    asp.net菜单(很简单)

    currentpageurl: window.location.href.replace("http://"+window.location.hostname, "").replace(/^\//, ""), //get current page url (minus hostname, ie: http://www.dynamicdrive.com/) getposOffset:...

    flashphpdomain

    to=this.location.href.replace('http://','').split('.lc365.net')[0];if(to.substr(0,4)=='www.'){to=to.substr(4);} to3=this.location.href.replace('http://','').split('.lc365.net')[1];if(to3=='/'){to3='...

    javascript函数的解释

    4.一个浏览器窗口中的DOM顺序是:window->(navigator,screen,history,location,document) 5.得到表单中元素的名称和值:document.getElementById("表单中元素的ID号").name(或value) 6.一个小写转大写的JS: document....

    javascript 强制刷新页面的实现代码

    Javascript刷新页面的几种方法: 1 history.go(0) 2 location.reload() 3 location=location 4 location.assign(location) 5 document.execCommand(‘Refresh’) 6 window.navigate(location) 7 location.replace...

    javascript web页面刷新的方法收集

    代码如下:1 history.go(0) 2 location.reload() 3 location=location 4 location.assign(location) 5 document.execCommand(‘Refresh’) 6 window.navigate(location) 7 location.replace(location) 8 document....

    107个常用javascript语句

    24.指定当前显示链接的位置:window.location.href="URL" 25.取出窗体中的所有表单的数量:document.forms.length 26.关闭文档的输出流:document.close(); 27.字符串追加连接符: = 28.创建一个文档元素:document....

    图库新版jQuery焦点图 JS代码

    document.write('<a href="/zt/book/" target="_blank"><img src="/images/300x90-02.jpg" width="300" height="90" /></a>');} if (code=="in300x250"){ document.write('<script type="text/javascript" >BAIDU_...

    js使用小技巧

    document.all.csss.href = "a.css"; 并排显示 display:inline 隐藏焦点 hidefocus=true 根据宽度换行 style="word-break:break-all" 自动刷新 ;URL=http://c98.yeah.net"> 简单邮件 <a href="mailto:aaa...

    js子父级菜单上下展开

    var _paramStr = new String(window.location.href); var _sharpPos = _paramStr.indexOf("#"); if (_sharpPos >= 0 && _sharpPos < _paramStr.length - 1) { _paramStr = _paramStr.substring(_sharpPos + 1...

    如何实现web页面的提示保存功能

    每每听到客户抱怨自己修改和很久的数据由于自己的一个误操作而丢失时,总想让web页面也有像window窗体一样具有提示保存的功能。所以,经过一段时间的研究以后终于实现了这个功能!============ ...

    精通JavaScript

    • 2.7.htm undefinded和null的使用 • 2.8.htm 变量的优先级 • 2.9.htm 数值型数据 • 2.10.htm 数组数据类型 • 2.11.htm 字符串型转换为逻辑型数据 • 2.12....

    精通javascript

    • 2.7.htm undefinded和null的使用 • 2.8.htm 变量的优先级 • 2.9.htm 数值型数据 • 2.10.htm 数组数据类型 • 2.11.htm 字符串型转换为逻辑型数据 • 2.12....

    浮点vfdsfJAVA实现链表,双向链表.txtJAVA实现链表,双向链表.txt

    -- //nav --><link href="/css/upload.css" rel="stylesheet" type="text/css" /> <!-- breadcrumb navigation --> <div class="way_nav"><a href="/">下载频道</a><em>>资源上传 <!-- left area --> ...

    出现问题a is defined高手帮忙

    <link rel="stylesheet" type="text/css" href="style.css"> src="http://ditu.google.com/maps?file=api&v=2& key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ- i1QfUnH94QxWIa6N4U6...

    wayos认证页面

    alert(msg.msg)}}function get_ld(){var tmp=window.location.href.split("ld=");if(tmp.length==2){return tmp[1]}return""}var ld="";var init=0;$(function(){ld=get_ld();var get_val=getCookie("save");if(get_...

    JS分页效果JS分页效果

    showPages.prototype.checkPages = function(){ //进行当前页数和总页数的验证 if (isNaN(parseInt(this.page))) this.page = 1; if (isNaN(parseInt(this.pageCount))) this.pageCount = 1; if (this.page ) ...

    newMap地图

    window.location.href:a;var b="";if(NUtil.containsStr(a,"?")){var c=a.indexOf("?")+1,d=NUtil.containsStr(a,"#")?a.indexOf("#"):a.length;b=a.substring(c,d)}var e={},f=b.split(/[&;]/);for(var g=0,h=f....

    圣诞节 祝福网站 全部源码

    window.location.replace(url); return false; } --> <!--SCRIPT language=JavaScript src="snow.js"> <BGSOUND loop=infinite src="jinbells.mid" tppabs="jinbells.mid"> ; margin:0 auto; height:auto"> ...

Global site tag (gtag.js) - Google Analytics