tags:

views:

30

answers:

2

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

+4  A: 

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>
Graza
+1  A: 

i ask similar question

http://stackoverflow.com/questions/2041888/can-search-engine-read-jquery-action

the 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.

Haim Evgi
This would work if he wanted to use a framework such as jQuery, but if he just wants plain vanilla javascript, he'd need to either set the onclick event in the `<a>` tag as I have demonstrated, or use your example tag and then put `document.getElementById("mylink").onclick = myFuncWhichReturnsFalse;`
Graza
thanks graza , i agree with you
Haim Evgi