Noscript Tag, JavaScript Disabled Warning and Google Penalty

我怕爱的太早我们不能终老 提交于 2019-11-27 11:06:09

Put the <noscript> content at the end of your HTML, and then use CSS to position it at the top of the browser window. Google will no longer consider it important.

Stack Overflow itself uses this technique - do a View Source on this page and you'll see a "works best with JavaScript" warning near the end of the HTML, which appears at the top of the page when you switch off JavaScript.

<noscript> is not meant for meaningless warnings like:

<noscript>
Oh, no! You don't have JavaScript enabled! If you don't enable JS, you're doomed. [Long explanation about how to enable JS in every browser ever made]
</noscript>

It's meant for you to provide as much content as you can, along with a polite mention that enabling JS will provide access to certain extra features. You'll find that basically every popular site follows this guideline.

James

I don't think using <noscript> is a good idea. I've heard that it is ineffective when the client is behind a JavaScript-blocking firewall - if the client's browser has JavaScript enabled the <noscript> tag won't activate, because, as far as the browser's concerned, JavaScript is fully operable within the document...

A better method IMO, is to have all would-be 'noscript' content hidden by JavaScript.

Here's a very basic example:

...
<body>

    <script>
        document.body.className += ' js-enabled';
    </script>

    <div id="noscript">
        Welcome... here's some content...
    </div>

And within your StyleSheet:

body.js-enabled #noscript { display: none; }

More info:

Somebody on another forum mentioned using an image for the warning. The way I see it, this would have three benefits:

  1. There wouldn't be any irrelevant text for search engines to index.
  2. The code to display a single image is less bulky than a text warning (which gets loaded on every page).
  3. Tracking could be implemented to determine how many times the image is called, to give an idea of how many visitors have JavaScript disabled or blocked.

If you combine this with something like the non-noscript technique mentioned by J-P, it seems to be the best possible solution.

Just wanted to post an interesting tidbit related to this. For a site of mine I have ended up doing something similar to what stack overflow uses, but with the addition of a "find out more" link as my users are not as technical as this site.

The interesting part is that following advice of people aboce, my solution ditched the noscript tag, instead opting to hide the message divs with javascript. But I found that if firefox is waiting for its master password, this hiding of the message is interupted, so I think I will go back to noscript.

prograhammer

If you choose a solution based on replacing the div content (if js is enabled, then the div content gets updated) rather than using a noscript tag, be careful about how google views this practice:

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

I'm not sure google will consider it deceptive, but it's something to consider and research further. Here's another stackoverflow post about this: noscript google snapshot, the safe way

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!