开发者

JavaScript redirect causes undesired search engine results

I have an HTML5 demo site (http://html5beats.com/) that uses JavaScript to detect certain HTML5 features. I do a redirect to a "please change or upgrade your browser" page if those features are not present, since they are critical to making the site work.

The problem is that some search engines (specifically Google) seem to follow the redirect. This results in a nasty "Your Browser is Not Supported" message as the main search result for my site.

Am I using JavaScript redirects incorrectly? Is there somethi开发者_Python百科ng I can do to tell Google and other search engines which page has the main site content?


First, you should use robots.txt to tell search engines those pages that you don't want listed:

  • http://www.google.com/support/webmasters/bin/answer.py?answer=156449

Second, you can also provide assistance to Google (and other search engines) in understanding your site by providing a sitemap:

  • http://www.google.com/support/webmasters/bin/answer.py?answer=156184

Third, you can also consider a quick-and-dirty method of catching the Google bot (and other web crawlers) through the navigator.userAgent property in JavaScript and preventing the redirect in those cases:

  • http://www.useragentstring.com/pages/Crawlerlist/

In the last case, don't do a direct comparison of the navigator.userAgent string. Rather, use indexOf to find the identifying URL in the user-agent string, e.g.:

function upgradeRedirect() {
 if (navigator.userAgent.indexOf("http://www.google.com/bot.html") != -1) return;
 document.location.href = 'upgrade.html';
}


It really comes down to the content you are serving to Googlebot given the user-agent they are crawling with. Perhaps a better strategy would be to load your regular content with your regular title tag etc. and then pop a modal dialogue over the page if the user doesn't support html5 with some links to download an html5 browser. That way your listing will still look respectable for site:http://html5beats.com/. BTW -- I really like your site/idea.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜