Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prevent-unload

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prevent-unload - npm Package Compare versions

Comparing version 0.0.2 to 0.0.3

1

lib/index.js

@@ -14,2 +14,3 @@ 'use strict';

listener = function listener(event) {
// for cross-browser solution, see: https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload
event.returnValue = message;

@@ -16,0 +17,0 @@ return message;

12

package.json
{
"name": "prevent-unload",
"version": "0.0.2",
"version": "0.0.3",
"description": "Prevent page unloading in simple way",
"main": "./lib/index.js",
"main": "lib/index.js",
"scripts": {

@@ -30,8 +30,8 @@ "test": "echo \"Error: no test specified\" && exit 1",

"devDependencies": {
"babel-eslint": "^5.0.0-beta6",
"babel-eslint": "^6.0.0-beta.6",
"babel-plugin-add-module-exports": "^0.1.2",
"babel-preset-es2015": "^6.3.13",
"eslint": "^2.0.0-alpha-2",
"eslint-plugin-babel": "^3.0.0"
"babel-preset-es2015": "^6.6.0",
"eslint": "^2.4.0",
"eslint-plugin-babel": "^3.1.0"
}
}
const defaultMessage = 'Are you sure?';
let listener = null;
let listener;
function preventUnload(message = defaultMessage) {
listener = (event) => {
// for cross-browser solution, see: https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload
event.returnValue = message;
return message;
};
if (listener) {
return;
}
listener = makeHandler(message);
window.addEventListener('beforeunload', listener);

@@ -16,8 +15,18 @@ }

function revoke() {
if (listener) {
window.removeEventListener('beforeunload', listener);
listener = null;
if (!listener) {
return;
}
window.removeEventListener('beforeunload', listener);
listener = null;
}
function makeHandler(message) {
return () => {
// for cross-browser solution, see: https://developer.mozilla.org/en-US/docs/Web/Events/beforeunload
event.returnValue = message;
return message;
};
}
export {

@@ -24,0 +33,0 @@ preventUnload as default,

Sorry, the diff of this file is not supported yet

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