stuart
stuart

Reputation: 1

HTML Link questions

When creating a link i need to find out if i can do the following:

<a href="page.html" onclick="javascript:ajax();">blah</a>

I want it so that if the user clicks on it, it will get the content as we described using ajax however, i want the search engine to be able to follow the link so that we still get maximum indexing.

I'm pretty sure it should work but would like clarification

Upvotes: 0

Views: 107

Answers (2)

Haim Evgi
Haim Evgi

Reputation: 125466

I asked similar question, where I got this answer from pekka:

The best way would be to degrade gracefully, e.g. by using a standard

<a id='mylink' href='xyz.html'>

link that points to the resource that is opened in the popup. You would then add the JQuery code to the link, causing it to open in the pop-up.

That way, even users that do not have JavaScript turned on can access your popup.

Most Lightbox clones like Thickbox work that way.

Upvotes: 1

Graza
Graza

Reputation: 5050

Set the href attribute of the link to the static page that you want the search engine to follow, then use the onclick event to do your javascript/ajax request for "human" users. As long as the onclick event returns false, the standard link won't be followed.

A good test of this would be turning javascript off and clicking the link - you should end up with what you want the search engine to see.

You don't need the "javascript:" string in the onclick attribute, it is only necessary if you are putting javascript in the href attribute. You should have something like:

<a href="page.html" onclick="ajax(this.href); return false;">blah</a>

Upvotes: 4

Related Questions