HTML5 API 之 history
*:first-child {
margin-top: 0 !important;
}
body>*:last-child {
margin-bottom: 0 !important;
}
/* BLOCKS
=============================================================================*/
p, blockquote, ul, ol, dl, table, pre {
margin: 15px 0;
}
/* HEADERS
=============================================================================*/
h1, h2, h3, h4, h5, h6 {
margin: 20px 0 10px;
padding: 0;
font-weight: bold;
-webkit-font-smoothing: antialiased;
}
h1 tt, h1 code, h2 tt, h2 code, h3 tt, h3 code, h4 tt, h4 code, h5 tt, h5 code, h6 tt, h6 code {
font-size: inherit;
}
h1 {
font-size: 28px;
color: #000;
}
h2 {
font-size: 24px;
border-bottom: 1px solid #ccc;
color: #000;
}
h3 {
font-size: 18px;
}
h4 {
font-size: 16px;
}
h5 {
font-size: 14px;
}
h6 {
color: #777;
font-size: 14px;
}
body>h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h4:first-child, body>h5:first-child, body>h6:first-child {
margin-top: 0;
padding-top: 0;
}
a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
margin-top: 0;
padding-top: 0;
}
h1+p, h2+p, h3+p, h4+p, h5+p, h6+p {
margin-top: 10px;
}
/* LINKS
=============================================================================*/
a {
color: #4183C4;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
/* LISTS
=============================================================================*/
ul, ol {
padding-left: 30px;
}
ul li > :first-child,
ol li > :first-child,
ul li ul:first-of-type,
ol li ol:first-of-type,
ul li ol:first-of-type,
ol li ul:first-of-type {
margin-top: 0px;
}
ul ul, ul ol, ol ol, ol ul {
margin-bottom: 0;
}
dl {
padding: 0;
}
dl dt {
font-size: 14px;
font-weight: bold;
font-style: italic;
padding: 0;
margin: 15px 0 5px;
}
dl dt:first-child {
padding: 0;
}
dl dt>:first-child {
margin-top: 0px;
}
dl dt>:last-child {
margin-bottom: 0px;
}
dl dd {
margin: 0 0 15px;
padding: 0 15px;
}
dl dd>:first-child {
margin-top: 0px;
}
dl dd>:last-child {
margin-bottom: 0px;
}
/* CODE
=============================================================================*/
pre, code, tt {
font-size: 12px;
font-family: Consolas, "Liberation Mono", Courier, monospace;
}
code, tt {
margin: 0 0px;
padding: 0px 0px;
white-space: nowrap;
border: 1px solid #eaeaea;
background-color: #f8f8f8;
border-radius: 3px;
}
pre>code {
margin: 0;
padding: 0;
white-space: pre;
border: none;
background: transparent;
}
pre {
background-color: #f8f8f8;
border: 1px solid #ccc;
font-size: 13px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
border-radius: 3px;
}
pre code, pre tt {
background-color: transparent;
border: none;
}
kbd {
-moz-border-bottom-colors: none;
-moz-border-left-colors: none;
-moz-border-right-colors: none;
-moz-border-top-colors: none;
background-color: #DDDDDD;
background-image: linear-gradient(#F1F1F1, #DDDDDD);
background-repeat: repeat-x;
border-color: #DDDDDD #CCCCCC #CCCCCC #DDDDDD;
border-image: none;
border-radius: 2px 2px 2px 2px;
border-style: solid;
border-width: 1px;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
line-height: 10px;
padding: 1px 4px;
}
/* QUOTES
=============================================================================*/
blockquote {
border-left: 4px solid #DDD;
padding: 0 15px;
color: #777;
}
blockquote>:first-child {
margin-top: 0px;
}
blockquote>:last-child {
margin-bottom: 0px;
}
/* HORIZONTAL RULES
=============================================================================*/
hr {
clear: both;
margin: 15px 0;
height: 0px;
overflow: hidden;
border: none;
background: transparent;
border-bottom: 4px solid #ddd;
padding: 0;
}
/* TABLES
=============================================================================*/
table th {
font-weight: bold;
}
table th, table td {
border: 1px solid #ccc;
padding: 6px 13px;
}
table tr {
border-top: 1px solid #ccc;
background-color: #fff;
}
table tr:nth-child(2n) {
background-color: #f8f8f8;
}
/* IMAGES
=============================================================================*/
img {
max-width: 100%
}
-->
HTML5 API 之 history
简介
可以操作浏览器的历史记录,在其中添加项目。配合新增的popstate事件,可以实现在不刷新页面的前提下动态的改变浏览器地址的Url和页面内容。
使用
var state = {};
state.name = 'history-1';
window.history.pushState(state,null,'history-1');
state.name = 'history-2';
window.history.pushState(state,null,'history-2');
window.addEventListener('popstate',myfunc,false);
function myfunc(e){
if(e.state){
alert(e.state.name);
}
}
history.pushState
var state = {};
state.name = 'history-1';
window.history.pushState(state,null,'history-1');
- 首先,我们创建了一个空对象。这个对象就是我们传给
pushState方法的第一个参数。它的作用是保存当前页面的一些信息,当我们通过前进或者后退按钮到达这个页面的时候,可以访问这个对象中保存的信息。在上面的栗子中,我们访问的是的它的name属性。 pushState的第二个参数,用来设置页面的标题,但是目前好像没有浏览器支持,所以我们传入一个null。- 第三个参数,是我们希望在地址栏中显示的url后面附加的字符串,这样,我们可以清晰的看到页面url的变化。
- 这样,一条历史记录就被我们添加了。
popstate
window.addEventListener('popstate',myfunc,false);当浏览器前进或者后退的时候触发
popstate是HTML5种新增的事件。当点击浏览器的前进或者后退时,触发改事件。该事件的默认参数是一个PopStateEvent对象。该对象中有一个state属性,包含历史记录中一个页面保存的信息。结合本文的例子来看,保存的就是我们创建的state对象。那么,我们就试着去访问一个这个对象,看看其中是否真的包含我们存进去的
state对象的信息。function myfunc(e){
if(e.state){
alert(e.state.name);
}
}
点击后退,屏幕弹框显示
history-1总结:HTML5 的
historyAPI可以方便的控制页面的历史记录,让我们有了在单页面中实现前进后退动作的更好方式。结合pushState方法的第一个参数,让我们构建单页面应用更加的心应手。
HTML5 API 之 history的更多相关文章
- 大熊君学习html5系列之------History API(SPA单页应用的必备------重构完结版)
一,开篇分析 Hi,大家好!大熊君又和大家见面了,(*^__^*) 嘻嘻……,这系列文章主要是学习Html5相关的知识点,以学习API知识点为入口,由浅入深的引入实例, 让大家一步一步的体会" ...
- 大熊君学习html5系列之------History API(SPA单页应用的必备)
一,开篇分析 Hi,大家好!大熊君又和大家见面了,(*^__^*) 嘻嘻……,这系列文章主要是学习Html5相关的知识点,以学习API知识点为入口,由浅入深的引入实例, 让大家一步一步的体会" ...
- HTML5 API's (Application Programming Interfaces)
New HTML5 API's (Application Programming Interfaces) The most interesting new API's are: HTML Geoloc ...
- Web开发者的最爱 5个超实用的HTML5 API
摘要:毫无疑问,HTML5已经成为当今最流行的一门技术,尤其是Web开发者们对HTML5的兴趣是日趋渐浓.HTML5的许多功能也都能在现代浏览器中得以实现.然而,作为开发者,除了关注HTML5的功能和 ...
- HTML5中的History对象
HTML5标准之前 基本操作 1.forward(number) 加载histroy列表中的下一个URL 2.back(number) 加载histroy列表中的上一个URL 3.go(number) ...
- HTML5+ API 学习
HTML5+ API 模块整理 API Reference 模块 中文 模块介绍 Accelerometer 加速计 管理设备加速度传感器,用于获取设备加速度信息,包括x(屏幕水平方向).y(垂直屏幕 ...
- 你可能不知道的5个功能强大的 HTML5 API
HTML5 新增了许多重要的特性,像 video.audio 和 canvas 等等,这些特性使得能够很容易的网页中包含多媒体内容,而不需要任何的插件或者 API.而其它的新元素,例如 section ...
- HTML5 API 是什么
HTML5 API 是什么 一.总结 1.html5有很多好的api可以用:例如绘图的canvas,获取地理位置的,获取手机电池信息的等等,后面用的时候可以百度 2.html5 API是什么:html ...
- HTML5 API——无刷新更新地址 history.pushState/replaceState 方法
尽 管是上面讲到的<JavaScript高级程序设计>(第二版)中提到,BOM中的location.path/query…… (window.location)在通过JavaScript更 ...
随机推荐
- C与Lua互相调用的时候,栈变化分析
1 C调用Lua函数的堆栈变化 例子 Lua文件中的函数 function testNewCounter2() return "第四个结果" end C中的例子 void t_n ...
- JMeter二次开发(2)-编写 JSON Assertion 插件
本篇文章主要介绍如何对JMeter进行二次开发,添加自己所需的功能.这里以Json验证为例进行说明.在web接口测试过程中,JSON的应用已经非常普遍,但原声的JMeter并没有提供Json及Json ...
- jboss7访问日志功能及使用goaccess工具分析
网络上虽然很多文章分别讲到jboss7的访问日志如何配置,goaccess工具怎么分析nginx/tomcat等日志.但将两者放在一起即“通过goaccess分析jboss访问日志”的倒是没搜索到. ...
- excel中单元格计算
首先,得明确excel中相对引用和绝对引用的概念,这里$符号起着关键作用,当在一个行或列的指示符前面加$则表示绝对引用,否则相对引用,具体: 1.相对引用,复制公式时地址跟着发生变化,如C1单元格有公 ...
- jquery学习记录
1.选择器实例 语法 描述 $(this) 当前 HTML 元素 $("p") 所有 <p> 元素 $("p.intro") 所有 class=&q ...
- Chrome调试(debugger)总是进入paused in debugger状态
在通过Chrome浏览器进行web前端开发时,我们会经常用到Chrome自带的debugger工具,但是经常按完快捷键(F12)后,页面会进入 paused in debugger状态,需要点击右上角 ...
- hbase常用运维命令
一,基本命令: 建表:create 'testtable','coulmn1','coulmn2' 也可以建表时加coulmn的属性如:create 'testtable',{NAME => ' ...
- Android IOS WebRTC 音视频开发总结(三五)-- chatroulette介绍
本文主要从技术角度介绍chatroulette,文章来自博客园RTC.Blacker,支持原创,转载请说明出处. 很多人不知道或没用过chatroulette,下面先来张界面截图让大家有个整体了解: ...
- 举例详解CSS中的的优先级
计算优先级 优先级是根据由每种选择器类型构成的级联字串计算而成的.他是一个对应匹配表达式的权重. 如果优先级相同,靠后的 CSS 会应用到元素上. 注意:元素在文档树中的位置是不会影响优先级的优先级顺 ...
- POJ C++程序设计 编程题#1 编程作业—文件操作与模板
编程题#1 来源: POJ (Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB 描述 实现一个三维数组 ...