user188962
user188962

Reputation:

Check if javascript is enabled in browser

I have this code which checks if js is enabled and redirects:

<noscript><meta http-equiv="refresh" content="0;url=http://www.domain.se/act.html"></noscript>

However, I wonder if this is SE friendly...

This because I have added my website url to yahoo recently, and instead of the title appearing in the search results, the text from "aktivera_javascript.html" above appears. Why is that?

Thanks

UPDATE:

If the code above isn't proper for checking js availability, then what other method should I use instead?

Upvotes: 2

Views: 12042

Answers (3)

Sebastian Thiele
Sebastian Thiele

Reputation: 160

I think you don't understand this tag. The content of noscript will only shown whether script (like JavaScript) isn't enabled. (Most) Search Engines can't understand JS and execute the content from noscript. So in your case they follow the url.

But be careful. With this method you can get penalty very fast. noscript is most used to show the user a notification, that javascript is disabled.

Upvotes: 0

Michael Baldry
Michael Baldry

Reputation: 2028

Personally, I think progressive enhancement is the way to go. Regardless of that you could try something like:

have people arrive at a non-js page by default. on the page have a script that is run on load:

<script type="text/javascript">
  window.location.href = 'page-with-javascript.html';
</script>

if the user has javascript enabled, they'll immediately be taken to the javascript friendly version.

but yeah.. progressive enhancement :)

Upvotes: 1

roryf
roryf

Reputation: 30150

The noscript tag is for user agents that can't execute script. Since the Yahoo! spider is one of those agents, I would guess (but can't be certain) that it respects the content of the noscript tag and therefore the HTTP-refresh directive contained within. The result is that it thinks your site lives at http://www.skuffen.se/aktivera_javascript.html, and displays that content in search results.

To fix the issue I would suggest either:

  1. Use progressive enhancement to ensure the basic content is available without Javascript, and layer advanced features on top. User agents without Javascript won't know any different, and those with will get a richer experience.
  2. Simply use the noscript tag as a warning rather than a full redirect to another page, see How to check browser's JavaScript is enabled or not.

Upvotes: 3

Related Questions