jan199674
jan199674

Reputation: 753

SEO in AJAX-links

I have a couple of questions about loading pages with AJAX and Jquery - heres what im using to load external .html-pages without reloading index-page:

$('a').click(function() {
    var page = $(this).attr("href");
        $("#content").load(page + ".html");
        return false;
});

<a href="page_one.html#page_one"> 1 </a>
<a href="page_two.html?page_two"> 1 </a>

<div id="content"> ..content from ext pages load here.. </div>

Q1: What does "return false" actually do here? Q2: Will the link "page_one.html#page_one" get indexed by Google? Q3: Should i be using hash-tag or ? in the links - both seems to be working so whats the differnece?

Hope someone has the answers

Upvotes: 1

Views: 349

Answers (2)

ChrisGulddahl
ChrisGulddahl

Reputation: 88

What does "return false" actually do here?

As John Conde explained this prevents the browser from following the hyperlink (e.g. to the page page_one.html#page_one rather than just loading it with AJAX).

Will the link "page_one.html#page_one" get indexed by Google?

Yes, the page page_one.html will. The #page_one part will be ignored. From any web crawler's perspective <a href="page_one.html#page_one"> 1 </a> is a completely standard anchor tag. However I'm guessing, that page_one.html is not a complete web page with navigation and stuff, but rather simply the page content? So you may not want to have that page indexed by Google.

Should i be using hash-tag or ? in the links - both seems to be working so whats the difference?

You shouldn't really need any of them. Since you are not using the hash fragment #page_one (in your javascript) you can remove it (it was useful for keeping track of AJAX state before HTML5 History manipulation was widely supported across browsers. Hash fragments can also be used for jumping to somewhere on the page. I.e. clicking an URL ending in #header1 would cause the browser to jump to an HTML element with id="header1" (but this is not relevant for your case). The ?page_one is usually used for supplying extra parameters for some server-side script (such as a PHP script) and thus it makes little sense for a flat HTML file.

Upvotes: 1

John Conde
John Conde

Reputation: 219804

What does "return false" actually do here?

Stops the browser from following through with the default action of the element which in this case is to follow the hyperlink

Will the link "page_one.html#page_one" get indexed by Google?

No. This does not meet Google's crawlable Ajax standard

Should i be using hash-tag or ? in the links - both seems to be working so whats the differnece?

It doesn't matter if it works. But if you want it to be search engine friendly you will need to find an alternative way to do this.

Upvotes: 0

Related Questions