How to Block JavaScript by Class Name in Firefox

The JavaScript language has a function that detects the user's browser. You use this function to block a script from running when your website readers use Firefox. This function lets you write browser-specific code, so users do not receive JavaScript errors when they use class code that is only specific for other browsers such as Internet Explorer or Chrome.

Instructions

    • 1

      Right-click the HTML file you want to use to detect the browser. Click "Open With" and select your preferred editor.

    • 2

      Create a variable that contains the browser name. The following variable contains "Firefox" if the user is using the Firefox browser:

      var browser = navigator.userAgent;

    • 3

      Create the "if" statement that excludes the Firefox browser when you use the JavaScript class. The following code creates the statement:

      if (browser != "Firefox")
      {

      }

      You place the class code within the brackets of the "if" statement. This if statement only runs the code if the browser is not Firefox.

    • 4

      Initialize the class in the if statement. The following code is an example of calling the "myClass" class in the JavaScript statement:

      var class = new myClass();

Related Searches:

References

Comments

Related Ads

Featured