Links · Link targets

Links that only work with JavaScript

This page reaches nine pages through nine different JavaScript methods and no ordinary links, so crawlers that do not run scripts never find them.

How this page is built

Each item below takes visitors to its own destination page using a different JavaScript technique. None of them is an ordinary link in the raw HTML. The destination pages are linked from nowhere else and are not in the sitemap, so they can only be found through these methods.

After a crawl, list the pages under /fixtures/js-link- that your crawler found. Each one it found tells you a method it follows; each one it missed tells you a method it does not. Crawlers that do not render JavaScript should find none of them.

  1. Button with an onclick attribute:
  2. Button with a click listener and data-href:
  3. Link with a javascript: href: javascript: link
  4. Anchor with no href and an onclick: Anchor with no href
  5. Link to # that navigates in a script: Link to #
  6. Button that calls window.open:
  7. Drop-down menu that navigates on change:
  8. Real link added to the page by a script:
  9. URL only in a JavaScript string:

Why it matters

Search engines discover pages by following links, and the links they trust are <a> elements with an href that holds a real URL. Google says it does not follow links made from click handlers, javascript: URLs or elements without an href. It may follow a real link that a script adds, but only after rendering, which can be delayed.

Pages reachable only through such methods may never be crawled or indexed, and they get no link value. Many crawl tools and most AI crawlers do not run JavaScript at all.

How to check it

Crawl the site with JavaScript rendering off, then on, and compare which /fixtures/js-link- pages each crawl found. In the browser, view the raw source and search for each destination URL: a crawler can only rely on URLs that appear in an href.

How to fix it

Use an <a href="…"> element with a real URL for every link to another page, and put it in the server-rendered HTML. Scripts can still add behaviour to those links, but the href must work on its own.

Back to all tests