onclick 

Summary: yes, Google indexes onclick links.

The conditions are that the information to resolve the onclick to a URL has to be available in the HTML page; not in a linked JavaScript file. The way it resolves should be simple-ish too.

To figure out what to do when there are certain events, certain moments, browsers watch for. When you hold your mouse over something (onmouseover), when a webpage has fully loaded (onload), or when you click on something (onclick), to name a few.

A browser knows pretty darn well what to do with those events but if we want, we can use those moments, those events, to start a piece of JavaScript code; that code can than do pretty much anything we like.

The OnClick event is triggered when you hold your mouse over an element on a webpage, and click (mouse button down, mouse button up).

The OnClick event can be attached to any HTML tag. Here's an example:

  • <div onclick="alert('hey, this works!!')">content</div>

Using the OnClick moment to do something with JavaScript, we can use JavaScript functions to send the browser to another URL. Like so:

  • <div OnClick="location.href='https://example.com'">content</div>

OnClick links are often used attached to a regular link where together with some other code they can open the link in a new window or send information to an analysis script to count downloads, for example.

  • <a href="#" OnClick="location.href='https://example.com'">

Yes.

Since 2009 Google looks for and finds OnClick links in any and all HTML tags. When found they will add the URL to their crawl.

If there is sensible "anchor" text then the text of the element will be used as anchor text.

The OnClick link also passes PageRank.

But Beware!

Google is the only one doing this so far.

Also, Google will only try to find the URL:

  • If the information is in the same HTML document
  • And if the functions to figure out what the OnClick leads to aren't too complex

Often finding yourself in a situation where you have to use an OnClick in an HTML document (as opposed to dynamically attached to it) may be the sign of programming gone wrong.

Conclusion

  • Google treats OnClick links pretty much like regular links:
  • They find them
  • They index them
  • And they pass PageRank and anchor text
  • For that to happen the OnClick event and all information needed to find out what URL it would lead to have to be available in the page
  • Having to use OnClick in an HTML document as opposed to attached to it may be a sign of a quick and dirty workaround
  • Having to use OnClick in an HTML document can Lead to usability issues

If you liked this you might enjoy Can I Have Numerical ID's In My URL Or None At All?

About the Author: Ruud Hein

I love helping to make web sites make it. From the ground up if needed. CSS challenges, server-side scripting, user and device friendly JavaScript tricks search engines have no problems with. Tracking how the sites perform and then figuring out how to make that performance and the tracking better. I'm passionate about information. No matter how often I trim my feeds in my feed readers (yes, I use more than one), I always have a couple of hundred in there covering topics ranging from design to usability, from SEO to SEM, from life hacks to productivity blogs, from.... Well, you get the idea, I guess. Knowledge and information management is close to my heart. Has to be with the amount of information I track. My "trusted system" is usually in flux but always at hand and fully searchable. My paid passion job at Search Engine People sees me applying my passions and knowledge to a wide array of problems, ones I usually experience as challenges. It's good to have you here: pleased to meet you!