Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does anyone still hide JS from old browsers?

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?

like image 563
nedlud Avatar asked Apr 20 '11 04:04

nedlud


People also ask

How can JavaScript codes be hidden from old browsers that do not support 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.

Can browser users see JavaScript?

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.

Is JavaScript the same in every browser?

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.


3 Answers

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.

like image 117
alex Avatar answered Oct 30 '22 19:10

alex


No. {insert extra chars here to meet limit for SO}

like image 29
JAAulde Avatar answered Oct 30 '22 19:10

JAAulde


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.

like image 27
Kevin Dolan Avatar answered Oct 30 '22 20:10

Kevin Dolan