admin管理员组文章数量:1136532
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.
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.
Share Improve this question edited Feb 20, 2013 at 19:28 j08691 208k32 gold badges267 silver badges280 bronze badges asked Mar 22, 2010 at 0:25 zeckdudezeckdude 16.2k44 gold badges146 silver badges194 bronze badges 4- 3 Not trying to be nuisance, but your site shouldn't really rely on JavaScript. Where's progressive enhancement? – James Commented Mar 22, 2010 at 0:40
- @J-P It all depends on your audience. Gmail must operate with people who don't have Javascript because it has Hotmail users. However Google Reader has a more web-savy user base, and can probably rely on Javascript being present. – Tyler Carter Commented Mar 22, 2010 at 0:41
- Anyone wanting to dev games with open web tools should consider this – Sam 山 Commented Mar 9, 2011 at 14:24
- 1 @James providing a no-js version of an entire site is a perfectly valid way to avoid relying solely on JS - a Boolean type of progressive enhancement maybe, but if the alternative site allows the users to complete their goals where's the problem? – Toni Leigh Commented Dec 10, 2015 at 19:27
7 Answers
Reset to default 81<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>
本文标签: How to redirect if javaScript is disabledStack Overflow
版权声明:本文标题:How to redirect if javaScript is disabled? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736966643a1957923.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论