<!DOCTYPE html>
<html> <head>
<meta charset="UTF-8">
<title></title>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<style type="text/css">
div {
width: 100px;
height: 100px;
border: 1px solid red;
margin-left: 200px;
margin-bottom: 20px;
} .demo1,
.demo3 {
background: green;
} .demo2,
.demo4 {
background: blue;
}
</style>
<script type="text/javascript">
$(function() {
$(".demo1").click(function() {
//可回退,替换当前页面
window.location.href = "https://www.baidu.com/";
});
$(".demo2").click(function() {
//可回退,替换当前页面
window.location.assign("https://www.baidu.com/");
})
$(".demo3").click(function() {
//刷新当前页面当取值为 true 时,将强制浏览器从服务器重新获取当前页面资源,
//而不是从浏览器的缓存中读取,如果取值为 false 或不传该参数时,
//浏览器则可能会从缓存中读取当前页面。
window.location.reload(true);
})
$(".demo4").click(function() {
//不可回退
window.location.replace("https://www.baidu.com/");
})
})
</script>
</head> <body>
<div class="demo1"> </div>
<div class="demo2"> </div>
<div class="demo3"> </div>
<div class="demo4"> </div>
</body> </html>

  

效果图:

网页布局

<p>操作成功</p>
<strong>5</strong><span>秒后回到主页</span><a href="javascript:history.back();">返回</a>

任务:

1.打开网页后,如果不做任何操作则返回到一个新的页面

var num=document.getElementsByTagName("strong")[0].innerHTML;
//获取显示秒数的元素,通过定时器来更改秒数。
function count(){
  num--;
  document.getElementsByTagName("strong")[0].innerHTML=num;
  if(num==0){
    location.assign("www.imooc.com");
  }
}
setInterval("count()",1000);

2.点击返回则返回到前一个页面

function backTo(){

  window.history.back();

}

location和history是window中的对象

location.assign()方法用来加载一个新的文档

history.back()方法可以加载历史列表中的前一个URL

window.location事件

 

一、最外层top跳转页面,适合用于iframe框架集

top.window.location.href("${pageContext.request.contextPath}/Login_goBack");

============================================================================================

二、window.location.href和window.location.replace的区别

1.window.location.href=“url”:改变url地址;

2.window.location.replace(“url”):将地址替换成新url,该方法通过指定URL替换当前缓存在历史里(客户端)的项目,
因此当使用replace方法之后,你不能通过“前进”和“后 退”来访问已经被替换的URL,这个特点对于做一些过渡页面非常有用!

三、强制页面刷新

1.window.location.reload():强制刷新页面,从服务器重新请求!

============================================================================================

四、window.location.reload();页面实现跳转和刷新

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.URL=location.href
这几个都可以刷新
window.location.reload();刷新
window.location.href=window.location.href;刷新
window.close();关闭窗口,不弹出系统提示,直接关闭 
window.close()相当于self属性是当前窗口
window.parent.close()是parent属性是当前窗口或框架的框架组
页面实现跳转的九种方法实例:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>navigate</title>
<script language="javascript">
    setTimeout('window.navigate("top.html");',2000);
    setTimeout('window.document.location.href="top.html";',2000);
    setTimeout('window.document.location="top.html";',2000);
    setTimeout('window.location.href="top.html";',2000);
    setTimeout('window.location="top.html";',2000);
    setTimeout('document.location.href="top.html";',2000);              
    setTimeout('document.location="top.html";',2000);
    setTimeout('location.href="top.html";',2000);
    setTimeout('location.replace("top.html")',2000);
    //window对象
        //document对象
            //location对象
                //href属性
                //1.window.document.location.href
                //2.window.document.location
                //3.window.location.href
                //4.window.location
               
                //5.document.location.href
                //6.document.location
                //7.location.href
                //8.window.navigate
                //9.location.replace
                //只要使用location方法,和任意的window对象,location对象,href属性连用,都可以页面的跳转//// 
</script>
</head>

<body>
页面将在2秒后跳转
</body>
</html>

解释:
location是个对象,比如本页的document.location和window.location的属性有    
  location.hostname   =   community.csdn.net 
  location.href   =   http://community.csdn.net/Expert/topic/4033/4033372.xml?temp=2.695864E-02 
  location.host   =   community.csdn.net 
  location.hash   =   
  location.port   =   
  location.pathname   =   /Expert/topic/4033/4033372.xml 
  location.search   =   ?temp=2.695864E-02 
  location.protocol   =   http: 
  可见href是location的属性,类别是string。

location和history的更多相关文章

  1. location 、history

    location.href= location.reload() history.go()  0   1  -1 history.back() history.forward() history.le ...

  2. match,location,history

    哇,平常写路由时基本就是简单的按照组件给的示例写,从来没有考虑为什么,又遇见了路由相关的问题,先记录一下问题,好好捋一下,哎,好香要个大佬来带带我呀,每次遇到问题要解决好久 问题: 判断是否登录之后跳 ...

  3. [browser location和history] 简单实现了个路由[转载]

    今天看了1下前面写的,好像缺乏交流性,周末再来弄吧 -0- 今天看了browser 的 location 和 history location属性 // //location.hash 性是一个可读可 ...

  4. JS---BOM基本知识 (顶级对象,系统对话框,加载事件,location对象, history对象, navigator对象)

    BOM JavaScript分三个部分: 1. ECMAScript标准---基本语法 2. DOM--->Document Object Model 文档对象模型,操作页面元素的 3. BOM ...

  5. BOM 3.1 location对象 | history对象 | navigator对象 | 定时器 | 三大系列

    JavaScript分三个部分: 1. ECMAScript标准---基本语法 2. DOM--->Document Object Model 文档对象模型,操作页面元素的 3. BOM---& ...

  6. Location 位置 history

    拆分出来地址  让地址各归其位 search案例 查找历史记录跳转

  7. javascript深入之location对象和history对象

    浏览器的location 和history对象: 一.location对象: 1>location.reload() 相当于按浏览器上的“刷新”(IE)或“Reload”(Netscape)键. ...

  8. backbone.Router History源码笔记

    Backbone.History和Backbone.Router history和router都是控制路由的,做一个单页应用,要控制前进后退,就可以用到他们了. History类用于监听URL的变化, ...

  9. 浏览器history操作实现一些功能

    返回拦截 功能:从广告进入到落地页后,给history增加一个页面,拦截返回动作 主要用到的是h5中的history对象,使用了pushState,和replaceState来操作. 并且加入了一些条 ...

随机推荐

  1. 几条学习python的建议

    熟悉python语言, 以及学会python的编码方式. 熟悉python库, 遇到开发任务的时候知道如何去找对应的模块. 知道如何查找和获取第三方的python库, 以应付开发任务. 学习步骤 安装 ...

  2. 循环select查询结果集

    --标记id --每次查询特定列比标记id大的第一条数据, --同时更新标记id,直到查询结果为空 ) set @id='' begin @id=id from T_SGZ where id>@ ...

  3. Exchanger学习

    Java并发新构件之Exchanger JDK API Exchaner 介绍 JDK API 解释 A synchronization point at which threads can pair ...

  4. 深入解析当下大热的前后端分离组件django-rest_framework系列二

    视图三部曲 一部曲 · 使用混合(mixins) 上一节的视图部分: from rest_framework.views import APIView from rest_framework.resp ...

  5. Maximum Subarray——经典

    Find the contiguous subarray within an array (containing at least one number) which has the largest ...

  6. Trapping Rain Water——经典的双边扫描问题

    Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...

  7. react生命周期函数使用箭头函数,导致mobx-react问题

    最近新人加入了项目,遇到了一个很奇怪的问题.mobx observable 属性,onChange的时候就是页面不会刷新. 试来试去,就是不知道什么原因,后来其他同事查到是因为componentWil ...

  8. Android学习之Android studio篇-Android Studio快捷键总结(mac)

    原文:http://blog.csdn.net/hudfang/article/details/52117065 符号代表键盘按键:⌘(command).⌥(option).⇧(shift).⇪(ca ...

  9. Ubuntu 16.04 apt-get搭建LAMP环境

    本文重点介绍在Ubuntu中使用apt-get安装LAMP(Ubuntu 16.04,Apache2.4.18,mysql5.7.12,php7.0.4)环境,所以不再介绍如何安装Ubuntu. 安装 ...

  10. AC日记——「SCOI2015」小凸玩矩阵 LiBreOJ 2006

    「SCOI2015」小凸玩矩阵 思路: 二分+最大流: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 300 ...