admin管理员组文章数量:1405413
Is it possible to put a noscript tag in a script tag ? Because I would like to perform a function that will check if JS is enable and if not it will redirect to an other link like this :
<script>
window.setInterval(function(){
<noscript>
<meta http-equiv="refresh" content="0; url=http://192.168.1.1/index.html" />
</noscript>
}, 5000);
</script>
Thanks
Is it possible to put a noscript tag in a script tag ? Because I would like to perform a function that will check if JS is enable and if not it will redirect to an other link like this :
<script>
window.setInterval(function(){
<noscript>
<meta http-equiv="refresh" content="0; url=http://192.168.1.1/index.html" />
</noscript>
}, 5000);
</script>
Thanks
Share Improve this question asked Nov 27, 2015 at 10:13 WonknUWonknU 271 silver badge6 bronze badges 5- 2 You've to rethink the logic. You can't put HTML tags in a script, nor the interval will be never executed, if JS is not enabled. – Teemu Commented Nov 27, 2015 at 10:14
- 1 What is the point of the setInterval in this? why not just use the noscript tag? – Aaron Commented Nov 27, 2015 at 10:16
- No, Anything inside the script tag will be parsed as javascript. – Matt Greenberg Commented Nov 27, 2015 at 10:17
- No, you can't. Whatever es inside script tag is treated as js code instead of html. say, how is your code supposed to work in js enabled browser? – Raj Kamal Commented Nov 27, 2015 at 10:18
- Only when you're high! /s – baNaNa Commented May 23, 2021 at 6:02
3 Answers
Reset to default 6No.
Aside from being unable to put markup inside a script in the first place, it wouldn't make any sense.
The script can't partially execute then discover that JavaScript is turned off entirely.
As other people mentionted, it is impossible and senseless.
If you want to redirect a user to another page after 5 seconds, if JavaScript is disabled, then add this HTML to your head
tag:
<html>
<head>
<noscript>
<meta http-equiv="refresh" content="5; url=http://www.sadtrombone./" />
</noscript>
</head>
</html>
5
in the beginning of this meta content
stands for 5 seconds.
Important note: According to XHTML Strict DTD, <noscript>
tag is disallowed in head
section. By using this code you make your HTML non-valid. However, it works on most browsers.
So, it is a good idea to avoid this. You can simply make a "Your browser is not supported" page with a link.
Good SO questions:
Redirect if no JavaScript
No-Javascript Detection Script + Redirect
Your logic is incorrect.
If you want to check js
you just need to use <noscript>
.
Inside script its not making any sense.
Edited:
What you are looking for is to check if user block js
after page loaded.
Ans:No you can't.
There is no way to check if user block js after your page loaded.
本文标签: javascriptnoscript tag in a script tagStack Overflow
版权声明:本文标题:javascript - noscript tag in a script tag? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744893122a2630900.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论