Skip to content
Determine whether a link click event will open in same or new tab/window.
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
dist
src
test
.gitignore
Gruntfile.js
README.md
bower.json
package.json

README.md

click-target.js

Determine whether a link click event will open in same or new tab/window.

Left-clicks with modifier keys and middle-clicks are considered new tab/window clicks.

Example

Click link and see console output on the test page: http://adjohnson916.github.io/click-target.js/test/.

Install

Either download, or install via [Bower][bower]:

$ bower install click-target

Include dist/click-target.js or dist/click-target.min.js in your page.

Usage

Supports [AMD][amd] and browser global (window.clickTarget).

Then use, for example:

var linkElement = document.querySelector('a');
linkElement.addEventListener('click', function (e) {
  var target = clickTarget(e);
  // => target == "_self" || target == "_blank"
});

Or with [jQuery][jquery]:

$('a').on('click', function (e) {
  var target = clickTarget(e);
  // => target == "_self" || target == "_blank"
});


[bower]: http://bower.io/ 
[amd]: http://en.wikipedia.org/wiki/Asynchronous_module_definition
[jquery]: http://jquery.com/
Something went wrong with that request. Please try again.