Determine if an anchor click was intended for staying on the current site
Determine if an anchor click was intended for staying on the current site.
The function this module exposes should be used in a click handler:
var stayOrGo = require'stay-or-go';windowaddEventListener'click'var a = stayOrGoevt;if !a return;evtpreventDefault;historypushStateapathname '' apathname;false;
If one or more of the following is true the return value will be
- The default action of the event was already prevented
- The user did not click the normal mouse button (when using a mouse).
- The user held one of the
Metakeys when clicking.
- The user did not click an anchor or a child elemnt of an anchor.
- The anchor clicked has a
hrefof the anchor is pointing to an external site.
Otherwise the return value is the anchor element clicked.