New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

history-events

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

history-events

Adds missing window.history events onpushstate, onreplacestate and onchangestate.

  • 1.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
378
decreased by-36.47%
Maintainers
1
Weekly downloads
 
Created
Source

history-events

Adds missing window.history events onpushstate, onreplacestate and onchangestate.

This module patches browser's window.history object and adds support for additional history events. You can use this module in a polymorphic applications (it only loads if inside a browser and does not raise an error on server side).

Setup

<script src="dist/history-events.min.js" type="text/javascript"></script>

If you are compiling assets using a bundler (e.g. webpack) then you just do the import inside your main file.

// es5
var history = require('history-events');
// es6
import history from 'history-events';

Usage

var history = require('history-events');

if (history.isHistorySupported()) {
  window.addEventListener('changestate', function(e) {
    console.log('URL changed');
  });

  window.history.pushState(null, null, '/login'); // `changestate` will be triggered
}

API

Window Events

  • onpopstate is triggered when browser's back/forward button is pressed.
  • onpushstate is triggered on window.history.pushState method call.
  • onreplacestate is triggered on window.history.replaceState method call.
  • onchangestate is triggered on window.history.pushState or window.history.replaceState method call or when browser's back/forward button is pressed.

Module Methods

  • history.isHistorySupported() returns true when window.history feature is supported by the environment.
  • addEventListener registes a new event.
  • removeEventListener unregistes a new event.
  • triggerEvent triggers an event.

Keywords

FAQs

Package last updated on 10 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc