catch-links
intercept local link clicks on a page
Last updated 11 years ago by substack .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install catch-links 
SYNC missed versions from official npm registry.

catch-links

intercept local link clicks on a page

This is useful for doing client-side pushState UIs.

example

Given some html:

<html>
  <body>
    <div>
      <a href="/a">aaa</a>
    </div>

    <div>
      <a href="/b">bbb</a>
    </div>

    <div>
      <a href="cc">cc</a>
    </div>
    
    <div>
      <a href="http://npmjs.org">npmjs</a>
    </div>
    
    <script src="bundle.js"></script>
  </body>
</html>

We'll intercept the relative links <host>/a and <host>/b, printing them. The external link to npmjs.org will go through as usual.

var catchLinks = require('catch-links');

catchLinks(window, function (href) {
    console.log(href);
});

methods

var catchLinks = require('catch-links')

catchLinks(element, cb)

Fire cb(href) whenever an anchor tag descendant of element with an in-server url is clicked.

href will always be a relative path rooted at the root path.

install

With npm do:

npm install catch-links

Use browserify to bundle this library into your project.

license

MIT

Current Tags

  • 2.0.1                                ...           latest (11 years ago)

6 Versions

  • 2.0.1                                ...           11 years ago
  • 2.0.0                                ...           11 years ago
  • 1.1.0                                ...           12 years ago
  • 1.0.0                                ...           12 years ago
  • 0.0.1                                ...           14 years ago
  • 0.0.0                                ...           14 years ago
Maintainers (1)
Downloads
Total 11
Today 0
This Week 0
This Month 8
Last Day 0
Last Week 6
Last Month 1
Dependencies (0)
None
Dev Dependencies (1)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE