How to redirect if javaScript is disabled?

I have a site which relies heavily on javaScript. I created a mirror site, which has all the JS as well as all the elements that require JS removed. What is a good, easy way to redirect users to the mirror site if they don't have javaScript enabled?

I tried this, but it doesn't seem very good:

<noscript>
  <meta http-equiv="refresh" content="0; URL=nojs/index.php">
</noscript>

I also tried to putting header-redirect into the noscript tag, but that didn't work.

Answers:

Answer

Make the no-JavaScript version of the site the default. Include a small script in there to redirect to the scripted site.

Or, abandon the use of a redirect entirely and go with Progressive Enhancement

Answer
<noscript>
    <p>This site is best viewed with Javascript. If you are unable to turn on Javascript, please use this <a href="http://sitewithoutjavascript.com">site</a>.</p>
</noscript>

Some people purposely disable Javascript, and you might want to give them a chance to turn it on before redirecting them.

Answer

Use this code that I came up with:

<noscript>
  <style>html{display:none;}</style>
  <meta http-equiv="refresh" content="0.0;url=nojs/index.php">
</noscript>

It uses style to block what's on the page so then people won't notice anything before it redirects. The only thing that annoys me is that I want something better than meta refresh as that can be blocked on some browsers like IE. A PHP header isn't really a solution as you can't put it in a noscript tag as it will just ignore it and write it out straight away.

Answer

What is your definition of "not very good"?

All my sites use:

<noscript>
  <meta http-equiv="refresh" content="0; url=http://www.sadtrombone.com/" />
</noscript>
Answer

I wouldn't do client-side redirection, as that might seem annoying to the user. Instead, what I would do is use <noscript> to show the content of this JS-less site on the same page. It may be more work, but it would definitely be a smoother experience.

Answer

I came up with a better solution than having to redirect the user as meta-refresh can be disabled in IE.

Put this in the HEAD:

<style>div#body{display:none;}</style>

Put this in the BODY:

<noscript>NO JAVASCRIPT CONTENT HERE</noscript>

<noscript><div id="body"></noscript>JAVASCRIPT CONTENT HERE<noscript></div></noscript>

That way the tags are where they're meant to be.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.