Does anyone still use the old
<!-- hide JS from old browsers -->
trick?
As I recall, this was targeted at people who used Netscape, or IE4.
I just checked out our stats and in the last month we had more people visit the site using "Playstation Portable " (4 visits) as their user agent than we had using Netscape (1 visit).
Is there any point in me even having the "hide" thing in my javascript?
Approach: After opening the <script> tag, we will use a one-line HTML style comment without any closing character ( <! – ). We will then write the JavaScript code that is to be hidden from older browsers. We will use the closing character with comment ( //–> ) before we close the script with the </script> tag.
As other have said, there is no way to protect JavaScript intended to run in a browser from a determined viewer. If the browser can run it, then any determined person can view/run it also.
The Anatomy of the JavaScript engine. EcmaScript specification tells how JavaScript should be implemented by the browser so that a JavaScript program runs exactly the same in all the browsers, but it does not tell how JavaScript should run inside these browsers. It is up to the browser vendor to decide.
No, you no longer need to do that.
Crockford also says...
Do not use the
<!-- //-->
hack with scripts. It was intended to prevent scripts from showing up as text on the first generation browsers Netscape 1 and Mosaic. It has not been necessary for many years.<!-- //-->
is supposed to signal an HTML comment. Comments should be ignored, not compiled and executed. Also, HTML comments are not to include--
, so a script that decrements has an HTML error.
No. {insert extra chars here to meet limit for SO}
The way I figure it, if you're designing an application with which one of the main selling points is javascript-based interactivity, there's no point in catering to older browsers.
Still, it's important to know the specific goals of your product. You need to know who you're targeting and make an informed decision as to whether or not it's worth it.
In any case, you should make an attempt to discover whether or not a browser has javascript enabled, and if not, inform them of why your site will not work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With