`
leonzhx
  • 浏览: 793663 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Manipulating History for Fun & Profit

 
阅读更多

1.   The HTML5 history API is a standardized way to manipulate the browser history via script. Part of this API — navigating the history — has been available in previous versions of HTML . The new parts in HTML5 include a way to add entries to the browser history, to visibly change the URL in the browser location bar (without triggering a page refresh), and an event that fires when those entries are removed from the stack by the user pressing the browser’s back button.

 

 

2.   If you change the URL , even through script, it triggers a roundtrip to the remote web server and a full page refresh. This takes time and resources, and it seems especially wasteful when you are navigating to a page that is substantially similar to the current page. Everything on the new page gets downloaded, even the parts that are exactly the same as the current page. There is no way tell a browser to change the URL but only download half a page.

 

3.   The history.pushState() function takes three parameters:

  a)   state can be any JSON data structure. It is passed back to the popstate event hander.

  b)   title can be any string. This parameter is currently unused by major browsers. If you want to set the page title, you should store it in the state argument and set it manually in your popstate callback.

  c)  u rl can be, well, any URL. This is the URL you want to appear in the browser’s location bar.

Calling history.pushState will immediately change the URL in the browser’s location bar without a full page refresh. Normally when the user navigates to a new page (with a full page refresh), the browser pushes the new URL onto its history stack and downloads and draws the new page. When the user presses the back button, the browser pops one page off its history stack and redraws the previous page. history.pushState fakes “moving forward” to a new URL .

 

4.   After you’ve used the history.pushState() function to push a fake URL onto the browser’s history stack, when the user presses the back button, the browser notices that a URL has been manually pushed onto the history stack. Instead of navigating to the previous URL and redrawing the entire page, the browser simply updates the location bar to the previous URL fire a popstate event on the window object. By the time your popstate callback is called, the global location property has already been updated with the previous URL .

分享到:
评论

相关推荐

    Series of MATLAB scripts and functions for manipulating ADCIRC

    Series of MATLAB scripts and functions for manipulating ADCIRC meshes, interpolation of bathymetry, and calculation of specific quantities.zip

    Functions-for-Manipulating-Data-in-PostgreSQL-Datacamp

    这个资料包"Functions-for-Manipulating-Data-in-PostgreSQL-Datacamp"显然聚焦于教导用户如何有效地利用PostgreSQL的各种内置函数来管理和分析数据。以下是关于PostgreSQL中数据处理函数的一些关键知识点: 1. **...

    C library for encoding, decoding and manipulating JSON data.zip

    JSON(JavaScript Object Notation)是一种轻量级的数据交换格式,被广泛用于Web服务和应用程序之间的数据传输。在C语言环境中,处理JSON数据通常需要借助专门的库,本压缩包提供的就是一个C语言编写的用于编码、...

    Itext in Action: Creating and Manipulating PDF

    关于PDF文件制作及操作的经典书籍,适用于java C#等多种语言,可以添加图片,水印,各种字体,报表,教你如何一步一步的成为PDF编程高手,真正的step by step,深入浅出,五步即可制作自己的PDF文件。

    SAS® Programming II: Manipulating Data with the DATA Step

    ### SAS® Programming II: Manipulating Data with the DATA Step #### 一、课程概述与基础知识复习 **1.1 概览** 本课程旨在深入讲解如何使用SAS® 的 DATA 步骤来处理数据,这对于数据清洗、转换以及分析至关...

    Python.for.Data.Analysis.2nd.Edition.2017.10

    Filled with practical case studies, Python for Data Analysis demonstrates the nuts and bolts of manipulating, processing, cleaning, and crunching data with Python. It also serves as a modern ...

    Manipulating Files_ManipulatingFiles_C++builder_

    标题"Manipulating Files_ManipulatingFiles_C++builder_"和描述"Manipulating Files - Delete"提示我们将深入探讨如何在C++Builder环境下进行文件操作,特别是删除文件的相关知识。 首先,理解C++Builder中的文件I...

    Python for data analysis

    , Python for Data Analysis is concerned with the nuts and bolts of manipulating, processing, cleaning, and crunching data in Python. It is also a practical, modern introduction to scientific computing...

    Python for Data Analysis

    , Python for Data Analysis is concerned with the nuts and bolts of manipulating, processing, cleaning, and crunching data in Python. It is also a practical, modern introduction to scientific computing...

    Manipulating light radiation from a topological perspective

    Manipulating radiation is important for a variety of optoelectronic applications, such as on-chip lasers, energy-efficient grating couplers, and antennas for light detection and ranging. Although ...

    OpenCV for Python Developers

    Manipulating pixels Scaling and rotating images Using video inputs Creating custom interfaces Thresholding Object detection Face and feature detection Template matching Skill Level Intermediate 2h ...

    CSAPP Lab1:Manipulating Bits实验材料

    **深入理解计算机系统(CSAPP)实验一:操作位(Manipulating Bits)** 在这个实验中,我们将探索计算机底层的位操作,这是理解计算机系统工作原理的关键。位是计算机中的基本单位,所有数据和指令都是由位组成的。...

    Packt.Python.for.Finance.2nd.Edition.2017

    It provides data structures for efficiently storing and manipulating tabular data. - **Python Modules Related to Finance**: Specific modules tailored for financial analysis are discussed, such as `...

    Beginning CSS: Cascading Style Sheets for Web Design, 2nd Edition(part1)

    It first guides you through the principles of sound CSS-based web design and the properties for manipulating the presentation of a document. You’ll then find out how to take your sites to a higher ...

    manipulating-dom-for-beginners:训练DOM操作的基本概念

    "manipulating-dom-for-beginners"训练课程旨在帮助初学者理解并掌握DOM操作的基础知识,这对于任何想要进行前端开发的人来说都是至关重要的。 1. **DOM结构**:DOM树是由节点构成的,每个HTML元素、属性、文本甚至...

Global site tag (gtag.js) - Google Analytics