开发者

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 hav开发者_JAVA百科e 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.


<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.


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.


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


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>


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.


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.


Just simply put this code to your html file

<meta http-equiv = "refresh" content = "2; url = https://www.google.com" />
<!DOCTYPE html>
<html>
   <head>
      <title>Redirection</title>
      <meta http-equiv = "refresh" content = "2; url = https://www.tutorialspoint.com" />
   </head>
   <body>
      <p>This page will redirect in 2 seconds.</p>
   </body>
</html>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜