


In HTML files, the history.pushState() method adds a state to the browser history.
pushState() takes three parameters: a state object, a title (now ignored), and an optional URL address . These three parameters will be examined in detail below:
state object —The state object is a JS object created by the pushState() method and related to the history record. When the user is directed to a new state, the popstate event is triggered. The event's state property contains the history's state object. (Translator's Note: In short, it stores JSON strings and can be used in popstate events.) The state object can be anything that can be serialized. Since Firefox will store these objects on the user's disk, so these state objects will be restored after the user restarts the browser, we impose a maximum string size of 640k on the serialized representation of the state object. If you pass a state object with a serialized representation greater than 640k to the pushState() method, this method will throw an exception. If you need more space, it is recommended to use sessionStorage or localStorage.
title — This parameter is now ignored by Firefox and may be used in the future. To allow for possible future changes, it is safe to pass an empty string. Of course, you can pass a short title for the state you want to transition to. (Translator's Note: Most browsers now do not support or ignore this parameter. It is best to use null instead)
URL - This parameter provides the address of the new historical record. Please note that the browser will not load this URL after calling the pushState() method, but it may do so later, such as after the user restarts the browser. The new URL does not have to be an absolute address; if it is relative, it must be relative to the current URL. The new URL must be under the same origin as the current URL; otherwise, pushState() will throw an exception. This parameter is optional. If it is not specified, it will be set to the current URL of the document.
Note: In Gecko 2.0 (Firefox 4 / Thunderbird 3.3 / SeaMonkey 2.1) to Gecko 5.0 (Firefox 5.0 / Thunderbird 5.0 / SeaMonkey 2.2), transferred objects are serialized using JSON. Starting with Gecko 6.0 (Firefox 6.0 / Thunderbird 6.0 / SeaMonkey 2.3), the object is serialized using the structured clone algorithm. This will allow a more diverse object to be transferred.
In some cases, calling pushState is equivalent to setting window.location = "#foo". In this case, both actions will create and activate another history record related to the current page.
But pushState() has other advantages:
The new URL can be any address under the same origin of the current URL. On the contrary, setting window.location will keep you on the same page unless you only change the hash.
If not necessary, you can not change the URL. Instead, set window.location Set to "#foo"; will only create a new history record if the current hash is not #foo.
You can associate arbitrary data with your new history entry. With the hash-based approach, you need to encode all of the relevant data into a short string. You can associate any data into your new history record. Using a hash-based approach, you encode all relevant data into a short string.
Please note that the pushState() method will never cause the hashchange event to be activated, even if the new URL is different from the old one only in hash.
In XUL, it creates a special XUL element.
In other documents, an empty URInamespace will be created.
SyntaxEDIT
history.pushState(state, title, url);
Sample EDIT
Created A new browser history set by state, title, and url.
var state = { 'page_id': 1, 'user_id': 5 }; var title = 'Hello World';var url = 'hello-world.html'; history.pushState(state, title, url);
【相关推荐】
1. 特别推荐:“php程序员工具箱”V0.1版本下载
4. 深入了解h5中history特性--pushState、replaceState
The above is the detailed content of Detailed introduction to the usage examples of history.pushState() in h5. For more information, please follow other related articles on the PHP Chinese website!

HTML5 code consists of tags, elements and attributes: 1. The tag defines the content type and is surrounded by angle brackets, such as. 2. Elements are composed of start tags, contents and end tags, such as contents. 3. Attributes define key-value pairs in the start tag, enhance functions, such as. These are the basic units for building web structure.

HTML5 is a key technology for building modern web pages, providing many new elements and features. 1. HTML5 introduces semantic elements such as, , etc., which enhances web page structure and SEO. 2. Support multimedia elements and embed media without plug-ins. 3. Forms enhance new input types and verification properties, simplifying the verification process. 4. Offer offline and local storage functions to improve web page performance and user experience.

Best practices for H5 code include: 1. Use correct DOCTYPE declarations and character encoding; 2. Use semantic tags; 3. Reduce HTTP requests; 4. Use asynchronous loading; 5. Optimize images. These practices can improve the efficiency, maintainability and user experience of web pages.

Web standards and technologies have evolved from HTML4, CSS2 and simple JavaScript to date and have undergone significant developments. 1) HTML5 introduces APIs such as Canvas and WebStorage, which enhances the complexity and interactivity of web applications. 2) CSS3 adds animation and transition functions to make the page more effective. 3) JavaScript improves development efficiency and code readability through modern syntax of Node.js and ES6, such as arrow functions and classes. These changes have promoted the development of performance optimization and best practices of web applications.

H5 is not just the abbreviation of HTML5, it represents a wider modern web development technology ecosystem: 1. H5 includes HTML5, CSS3, JavaScript and related APIs and technologies; 2. It provides a richer, interactive and smooth user experience, and can run seamlessly on multiple devices; 3. Using the H5 technology stack, you can create responsive web pages and complex interactive functions.

H5 and HTML5 refer to the same thing, namely HTML5. HTML5 is the fifth version of HTML, bringing new features such as semantic tags, multimedia support, canvas and graphics, offline storage and local storage, improving the expressiveness and interactivity of web pages.

H5referstoHTML5,apivotaltechnologyinwebdevelopment.1)HTML5introducesnewelementsandAPIsforrich,dynamicwebapplications.2)Itsupportsmultimediawithoutplugins,enhancinguserexperienceacrossdevices.3)SemanticelementsimprovecontentstructureandSEO.4)H5'srespo

The tools and frameworks that need to be mastered in H5 development include Vue.js, React and Webpack. 1.Vue.js is suitable for building user interfaces and supports component development. 2.React optimizes page rendering through virtual DOM, suitable for complex applications. 3.Webpack is used for module packaging and optimize resource loading.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft