Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Determine if an anchor click was intended for staying on the current site

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 index.js
Octocat-spinner-32 package.json
README.md

stay-or-go

Determine if an anchor click was intended for staying on the current site.

build status dev dependency status

browser support

Example

The function this module exposes should be used in a click handler:

var stayOrGo = require('stay-or-go');

window.addEventListener('click', function (evt) {
  var a = stayOrGo(evt);
  if (!a) return;

  evt.preventDefault();

  history.pushState(a.pathname, '', a.pathname);
}, false);

If one or more of the following is true the return value will be undefined:

  • The default action of the event was already prevented (event.preventDefault()).
  • The user did not click the normal mouse button (when using a mouse).
  • The user held one of the Ctrl, Shift, or Meta keys when clicking.
  • The user did not click an anchor or a child elemnt of an anchor.
  • The anchor clicked has a target attribute.
  • The href of the anchor is pointing to an external site.

Otherwise the return value is the anchor element clicked.

License

MIT

Something went wrong with that request. Please try again.