PDA

View Full Version : SEO for dynamic ajax content



emmahiggi
04-21-2010, 10:30 PM
1) Script Title: Dynamic Ajax Content

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

3) Describe problem: Hi there, I have used the ajax script in my website and it's working and looking great, the only thing is my client wants the site to be better optimised. I have been reading up about using hash fragments

http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=174993

but haven't been able to find out how to use this method in an existing site. I don't think you can just add !# and the name of the page again. Would anyone know another way to go about getting the external pages indexed? or even shed a bit of light on how to implement the hash fragments. Any advice would be appreciated.

Cheers
:):)

jscheuer1
04-22-2010, 02:49 AM
I know what you're talking about as regards SEO, but am unfamiliar with this hash business.

However, to get this script to be SEO friendly and have its imported pages be indexed is easy. Instead of using the syntax as described on the demo page, ex:


<a href="javascript:ajaxpage('test.htm', 'contentarea');">test</a>

Do it like so:


<a href="test.htm" onclick="ajaxpage(this.href, 'contentarea'); return false;">test</a>

That way users without javascript, and spiders will be able to access the page directly. So it will get indexed, and be available to non-javascript users.

If you don't want it available to non-javascript users though, you don't want it indexed anyway. If a page is indexed, folks with or without javascript can navigate to it directly from the search engine's results page.

emmahiggi
04-26-2010, 09:55 PM
Hi John,

Thanks a million for the reply, I tried it out and the problem is that I'm taken to the page on its own now rather than in the container on the nice index page I made. Do you know is there a way around this? As in if a page is showing up in search results and the user clicks on it they are taken to the htm page which is not in its nice container.

I'm still trying to figure out this hash fragment thing that Google has introduced but there isn't much detail on how to implement it. I'll post it if I figure it out because the seo is the only drawback to this dynamic script which I think is brilliant otherwise.

Cheers:):)

jscheuer1
04-27-2010, 06:08 AM
The Google information you cite appears to refer to their suggested methods of AJAX implementation. See the FAQ:


What if my app doesn't use hash fragments?

On the same Google FAQ page you linked to for some of those methods.

If you did what I suggested though with the Dynamic Ajax content script, things should be fine on your 'top' page, but yes:


. . . it will get indexed, and be available to non-javascript users.

If you don't want it available to non-javascript users though, you don't want it indexed anyway. If a page is indexed, folks with or without javascript can navigate to it directly from the search engine's results page.

To avoid that, one could put a javascript on the external pages that would switch to the 'top' page, and/or a meta refresh tag that would do the same.

To have that code load in the external page to your 'top' page's content division would require a fair amount of modification to the Dynamic Ajax content script, or 'front end onload' code for the 'top' page.

There is a script:

http://www.dynamicdrive.com/dynamicindex17/ajaxtabscontent/index.htm

That allows you to load a tab based upon the URL. If using that script, no modification would be required, you could just use a simple javascript location.replace or meta refresh to load in the desired URL from the external page to switch to the 'top' page with the external content loaded in the 'top' page's content area.

jscheuer1
04-27-2010, 02:12 PM
As an example of the code that could be used with the Dynamic Ajax Content script, you could put this on your 'top' page:


<script type="text/javascript">
(function(){
var q;
function getQval(n) {
if(typeof n !== 'string'){
return null;
}
var r = new RegExp('[?&;]' + n + '=([^&;#]*)'), m = location.search;
return (m = r.exec(m))? unescape(m[1]) : null;
}
if((q = getQval('loadpage'))){
function loadpage(){
q = q.split('::');
ajaxpage(q[0], q[1]);
}
if(window.addEventListener){
window.addEventListener('load', loadpage, false);
}
else if(window.attachEvent){
window.attachEvent('onload', loadpage);
}
}
})();
</script>

Then, and this part is a little tricky because you need to customize it a bit, on your external pages you can put:


<script type="text/javascript">
location.replace('../index_3col.htm?loadpage=' + encodeURIComponent(location.href + '::centercolumn'));
</script>

<meta http-equiv="refresh" content="0;url=../index_3col.htm?loadpage=ajaxfiles/external3.htm::centercolumn">

Highlighted and red are the path to your 'top' page from the external page. You may use the absolute path here if you like. Highlighted and green is the path to the external page from the top page, this may also be absolute. Highlighted and black are the name of the content area you wish to populate on the top page.

What this will all do is that if someone gets to your external page via a search engine (or any other way other than by loading it into your 'top' page), it will load into the 'top' page, except if they have javascript disabled. In that case it will load the 'top' page, where presumably you will have a noscript tag telling them that "The requested content and/or functionality of this page cannot be achieved without javascript enabled".

emmahiggi
05-27-2010, 10:28 AM
Hi John,

Cheers for all the help, I tried the solution you suggested and it broke my heart, in the end I optimised each page and put a redirect code

<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.site.ie">

Works fine.

Thanks again
Emma

jscheuer1
05-27-2010, 11:58 AM
Broke your heart? How? It's workable. I may have made an error in it somewhere though. If so, that could be fixed.

miow
06-07-2010, 10:15 AM
Hello there and Hi John!

I'm new here and i've searched a long time to find this thread. And first of all:
ThAnK YoU JoHn!!! ;)
It works great for me but i've just still a question to that all.

Well, after i built it all in my pages and my links now correct loads the content i have a question for a marker like an anchor.

IF i now click a link, it is all ok and my content loads in the div. Ok!
BUT if i copy this Link in the browsers url bar (or just click the middle mousebutton, you now this for sure) the contents also loads fine, but the site is now on top. I don't want this.

So i tried it out with an anchor and doesn't works in any way! -.-"
With or without your "update" of the Script.

Do you know something about a solution about this?

Also i got the problem now, that the anchor not again works. (with normal link without the scripts -> index.php#anchorname) Just one times and thats it. -.-"

Gnah, i really need help.
So with or without an anchor, but the extern loaded file with your script has to be load on a particular place on my site.
How can i realized that?

Thank you very much!

Best regards, miow


EDIT:
Ah before i forget:
After i click the link extern in new tab/browserwindow, there's a loooong link now like this:

http://domain.tld/index.php?loadpage=http%3A%2F%2Fdomain.tld%2Fincludes%2Flink.html%3A%3Aincludes
Is there a solution to say the script, the link should seems to be look normal?
Thank you!

EDIT 2:
And is it possible to add a infomessage if the user without Js on my website tried to navigate? I mean in the AJAX-Script and not with <noscript></noscript>.
Thx!

jscheuer1
06-07-2010, 07:21 PM
I think I understand what you are asking as far as the main part of your question, but it would be best if I had a link to your page to see what's happening there for sure.

As to your edits:


No, there is no way to avoid that, but it is a normal link. Many pages have links like that. The shorter you make your paths and filenames, the shorter it will be.


No, you cannot add a message or anything via javascript that will be seen by people without javascript.

miow
06-07-2010, 07:54 PM
I think I understand what you are asking as far as the main part of your question, but it would be best if I had a link to your page to see what's happening there for sure. [...]

Hello jscheuer1!

First of all: Thank you very very much that you've answered me (to me?).
I'm from north-germany and it's a bit hard for me with my really low knowledge to write the right contents, for asking some stuff about Js, html, php and so on.

So i have think about my last questions and i revise my previous questions.
(thx god for google-translate ^_^ )

Because.....
I've built a <noscript>here example sentence/content for no-Js-users, they can't use my page('s)</noscript> and that is so far ok for me.
The "Anchor", so i leave it to yourself (is this right? i meant, i let it be...it's google-translate! ^.^)

So far so on!

In related with, "two times "no" from your answers", i've decided to: "that's alright for me and i understood"
I mean....it's just perfect. Your whole script is perfect and....well.... it's all what i've ever searched for really really many months. Really!

So i've just have to say thank you, to you!
(sorry for the commas i set, because i have no clue about setting commas in english language!)

For all the other problems i have to ask at least:
Could i perhaps use "mod_rewrite" for that?
I mean, it looks a bit strange and yeah, i know that a couple of websites getting this strange links IF the user click for a new tab/window. (or just google webtools using without Js....they links are reaallllllyyyy strange! ^_^)

But i know for sure, it can be avoid. In any way..... *i think so*

I search the internet further for that and if i have a solution for that:
"I'll be back!" :D :cool:

(and if you still interested for looking my page, you can ask me via PN. I do not really want to write my URL inhere. ^_^ Annnd......it's all in german language. ;-) )

But anyways: ThAnK YoU VeRy MuCh for all your support!
Thx!!!

Best regards und einen schönen Abend noch aus Nord-Deutschland, miow ;)

jscheuer1
06-08-2010, 12:03 AM
Best regards und einen schönen Abend noch aus Nord-Deutschland, miow

Ah Deutschland, land of my ancestors, at least some of them. (I had some German in school, but had to Google Translate your message to get its full meaning. Thanks and a good evening to you too.)

I don't know enough about mod-rewrite to answer that. The script requires the information in the URL. If the script can still get that information with mod-rewrite, it will work. My limited understanding of mod-rewrite is that the script will not get the information it needs. But I could be wrong about that.

As for the main question, we can use an anchor, but that anchor's hash (#whatever) has to be at the end of the URL and there must be a named anchor on the 'top' page by that name, ex:


<a name="whatever"></a>

This should be located near the spot where your content division is on the 'top' page. Like:


<a name="whatever"></a>
<div id="centercolumn"></div>

We then could do (addition highlighted):


<script type="text/javascript">
location.replace('../index_3col.htm?loadpage=' + encodeURIComponent(location.href + '::centercolumn#whatever'));
</script>

<meta http-equiv="refresh" content="0;url=../index_3col.htm?loadpage=ajaxfiles/external3.htm::centercolumn">

If your noscript tag on the 'top' page is located in or near the content division:


<a name="whatever"></a>
<div id="centercolumn"><noscript>Javascript required for viewing this content.</noscript></div>

You could also add the named anchor's hash to the meta tag used by non-javascript folks:


<meta http-equiv="refresh" content="0;url=../index_3col.htm?loadpage=ajaxfiles/external3.htm::centercolumn#whatever">

miow
06-08-2010, 09:30 AM
Hi John!
...and good morning. ;)

First i tried out the anchor problem and your proposed solution.
A "normal" anchor link works fine but not the Js one you wrote.
BUT if i disable Js, the link (through the meta line) works!
Seems now only to be a problem in:

<script type="text/javascript">
location.replace('../index_3col.htm?loadpage=' + encodeURIComponent(location.href + '::centercolumn#whatever'));
</script>


Well, how i said the anchor works only without Js and if i take a very normal link like <a href="#anchor">Link</a>.
Incredible. :D
~~~
The mod_rewrite "problem" is less a problem by it self, because i start up a thread in a german forum about this.
The only problem by this are the german people. They won't help very well or not at all. So i have to see how i can generally "activate" mod_rewrite. :D
~~~
But the only problem is just, why the anchor doesn't works with activated Js.

Thank You!


Best regards, miow

jscheuer1
06-08-2010, 02:23 PM
I believe it is an encoding problem. I mistakenly encoded the hash. Instead of:


location.replace('../index_3col.htm?loadpage=' + encodeURIComponent(location.href + '::centercolumn#whatever'));

do it:


location.replace('../index_3col.htm?loadpage=' + encodeURIComponent(location.href + '::centercolumn') + '#whatever');

miow
06-08-2010, 02:47 PM
That works, bro! Thanks!

But it works only if i load this windows extern and not in the main index.

Maybe a further mistake i forgot to wrote. I'm really sorry about this.
Anywhere here maybe?

onclick="newload(this.href, 'includes'); return false;">

jscheuer1
06-08-2010, 06:43 PM
That works, bro! Thanks!

But it works only if i load this windows extern and not in the main index.

Maybe a further mistake i forgot to wrote. I'm really sorry about this.
Anywherer here maybe?

onclick="newload(this.href, 'includes'); return false;">

I'm not sure what you are asking here. I think I do, but I'm not sure. If this is a link already on the 'top' page, you have two choices:


onclick="newload(this.href, 'includes'); location.hash = '#whatever'; return false;">

Which is the best solution if it works. Or, since you already have it setup to transfer back to the 'top' page, just get rid of the onclick event entirely.

But I would be inclined in a case like this to put my links like this near the content area. That way the page wouldn't need to shift its position.

As I say though, I might not be understanding your question. If so, please explain in more detail.

miow
06-09-2010, 03:12 AM
John?

!!! ThAnK yOu VeRy MuCh !!!

You're great, really, believe in me. ;)
Now all my problems are solved and anything works just perfect.
It was a hard but funny way to understand me, i guess.
Aber es hat sich gelohnt! :D (google-translate says: "but it was worth it")

Last thing what i have to do now, is a smooth scrolling to the anchor. But that's another story and i'm sure i can fix this with my own knowledge, because i still have a "scrolling-script" on my old Homepage. (it's the "prototype" framework "scriptaculous") Edit: Just testing around and i have to say that doesn't work. Haha, well, whatever. I let it be.

However: Thank you very much!


Best regards, miow (aka the german who never knows to articulate :D )

miow
08-20-2011, 02:46 PM
I'm back after one year. ^^

Hi there!

So i got a new problem.
It's a strange behavior with this part...

<meta http-equiv="refresh" content="0;url=../index.php?loadpage=FOLDER/TargetSite.html::includes#anchor" />

... only in the new Opera and Safari.

If i try to load my page now in IE and FF (both up-to-date), it looks normal and the behavior is still normal, too.
But in frickin' Opera and Safari, the page reloads and reloads and reloads.
So i have to delete the meta refresh and it's working again normal.
But without re-direct of course, if Js disabled and calling the site directly.
Hope you know what i mean?

So is there another solution to prevent endless reloading or have i to re-edit all my 50 pages and delete this meta refresh part?
I could live with that, but it's a problem i would love to solve it. ;)
Thank you very much!

EDIT:
Ok, i got it.
Just adding "noscript" before and after the meta refresh, fix this problem. ;)