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.