1

Because not all browsers support JavaScript, we need a way to hide JavaScript from those browsers. If we do not JavaScript from those browsers, those browsers will treat JavaScript as page's content and thus display that code on the web page. How could i do that?

R.J. Dunnill
  • 2,049
  • 3
  • 10
  • 21
  • 1
    Browsers that don't support JavaScript won't run JavaScript so you should design your site to be non-JavaScript first, and then add the JavaScript capabilities (bells and whistles/AJAX etc.) later. Additionally, have you obtained statistics of your audience that makes it worthwhile you exploring such a solution. if your non-JavaScript audience is a very small percentage then, surely, you should be encouraging them (or even not bother making your site work for those who refuse) to update and use a mdoern browser. – Kinnectus May 29 '19 at 12:01
  • 2
    Are there really still browsers in use that do not support javascript or one of its close cousins (jscript, ecmascript)? – Jeff Zeitlin May 29 '19 at 12:21
  • Not absolutely certain, but as far as I am aware, text mode browsers are just about the only "modern" browsers that don't support JavaScript. That said, some people do block JavaScript with extensions. – Anaksunaman May 29 '19 at 14:27
  • @JeffZeitlin If I run umatrix or some other JavaScript blocker add-on, a site should be able to handle it. How else am I going to keep a bitcoin miner and or malicious embeded script from exploiting me. – zero298 May 29 '19 at 19:53

2 Answers2

0

Since JavaScript detection can be unreliable if done server-side, the best option is likely to use the <noscript> HTML tag. As detailed in this w3schools article, you could use something like:

<script>
document.write("Hello World!")
</script>
<noscript>Your browser does not support JavaScript!</noscript>

<noscript> is a generally well-supported HTML 4 tag and should be available in most major browsers, even older ones (since IE6+, Firefox 2+, Chrome 1+, etc.).

Anaksunaman
  • 236
  • 5
  • 13
0

HTML comment can be used in the script tag :

<script language="JavaScript">
 <!-- 
  document.write(new Date( ));
 // -->
</script>
Slai
  • 22,144
  • 5
  • 45
  • 53