I want to stop rendering the page and exit when the user's browser doesn't have JavaScript enabled or support, I want it like how exit() works in PHP. Is it possible via HTML?
You can do this:
<noscript>
<style type="text/css">body { display: none; } </style>
<meta http-equiv="refresh" content="0; url=http://redirectpage.com/">
</noscript>
No, that's not possible. What you could do, however, is add a stylesheet blanking out the page inside a <noscript>
tag:
<noscript>
<style>
* { display: none; }
</style>
</noscript>
Of course that would hide everything; not just stuff that occurs later on the page.
Another option that's very common is adding a no-js
CSS class to the <body>
tag which you remove as early as possible using JavaScript. That was you can properly create CSS rules to show/hide elements based on the (non-)existence of that class.
technically wrong but there is some browser support.
<noscript>
<meta http-equiv="refresh" content="0;url=noscript.html">
</noscript>
Here's how you use the noscript tag:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" >
// [whatever JS is appropriate]
</script>
<noscript>
<!-- Browser doesn't support JavaScript, so go elsewhere -->
<meta http-equiv="refresh" content="0;url=http://some.other-website.com/">
</noscript>
</head>
<body>
.... The rest of the HTML body
</body>
</html>
This only works in the <head> section with HTML5.
I think it's better to use ThiefMaster's and Dagon's concept together, as fallback support