Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including exitscript with all npm packages installed. Try it out:

var exitscript = require("exitscript")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

exitscript v1.1.7

A client-side popup warning for users clicking on non-government external links.

Exit Script

A client-side popup warning for users clicking on non-government external links.

Installation

  1. Install npm.
  2. npm install --save exitscript
  3. The browser-ready file will be at: node_modules/exitscript/exitscript.min.js

Usage

Here is an example of usage. IMPORTANT: This must go at the bottom of the page, just before the closing tag.

<script type="text/javascript" src="/path/to/exitscript.min.js"></script>
<script type="text/javascript">
  exitscript({
    title: 'You are now leaving this agency website.',
    content: '<p>You are about to access: {url}</p>',
    delay: 5
  });
</script>

Note the text {url} in the 'content' property. This is the only "dynamic" part of the content, and this text is replaced with a link to the external target.

One alternative option is possible: "click", which should be a javascript function that takes an href, and handles all of the popup behavior. This is only useful for cases where you already have your own popup behavior implemented and just need this library to add it to all external non-government links. If you take this approach, the snippet would simply be:

<script type="text/javascript" src="/path/to/exitscript.min.js"></script>
<script type="text/javascript">
  exitscript({
    click: myPopupFunction
  });
</script>

Development

To work on this library, you need to install npm.

To get the project's dependencies, in the project's root type:

npm install

Then edit the lib/index.js file as needed. To compile the library to the user-facing exitscript.js file, type:

npm run build
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free