Chrome does not support the browser name feature in the Javascript window navigator

Many believe that the javascript navigator function can be used to retrieve all browser-related properties of a particular machine. I attempted to do so myself, which you can find here:

<!DOCTYPE html>
<html>
  <body>
    <p id="demo"></p>
    <script>
      document.getElementById("demo").innerHTML =
        "Name is " + navigator.appName +
        "<br>Code name is " + navigator.appCodeName;
    </script>
  </body>
</html>

When attempting to extract the browser name, I noticed that when opened in Chrome, the value returned for navigator.appName was Mozilla. So my question remains: how can one retrieve the app name as 'Chrome' instead?

Answer №1

Here is a snippet of code you can use to identify your browser:


function myFunction() { 
    if((navigator.userAgent.indexOf("Opera") || navigator.userAgent.indexOf('OPR')) != -1 ) {
        alert('Opera');
    } else if(navigator.userAgent.indexOf("Chrome") != -1 ) {
        alert('Chrome');
    } else if(navigator.userAgent.indexOf("Safari") != -1) {
        alert('Safari');
    } else if(navigator.userAgent.indexOf("Firefox") != -1 ) {
        alert('Firefox');
    } else if((navigator.userAgent.indexOf("MSIE") != -1 ) || (!!document.documentMode == true )) {
        alert('IE'); 
    } else {
        alert('unknown');
    }
} 

I hope this helps you with identifying your browser.

Thank you.

Answer №2

Retrieve it using navigator.userAgent

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Avoiding unauthorized cookie access via browser console

Is it possible to prevent unauthorized access to the value of cookies using document.cookie from the browser's console? What security measures can be implemented to secure the cookies? https://i.sstatic.net/gUmSb.png ...

Warning: Javascript prompt for leaving website

I am currently working on an application and I would like to implement a popup that will appear when a link with the class "extlink-modal-trigger" is clicked. This popup will display a quick warning message, similar to how Facebook handles external links, ...

Ways to combine two JavaScript objects

Having trouble with JavaScript objects - I am trying to combine two objects with the same structure, both of which are strings. Here they are: data1 = '{"display:[{"counter":"A023","token":"001"}]"}' data2 = '{"display:[{"counter":"A013","t ...

Error in AngularJS v1.2.5 when using textarea with placeholder attribute in IE11

Having trouble with an Angular JS v1.2.5 form that is not functioning in IE11, despite working perfectly in Firefox, Chrome, and Safari. The issue seems to be related to using interpolation inside the placeholder attribute of a textarea. <body ng-con ...

Is there a way to retrieve the previous URL using JavaScript?

Is there a way to retrieve the previous URL in a Next.js project? I came across this, but it always returns the base URL (http://localhost:3000/) when using document.referrer. Another approach I tried was pushing a state into window.history based on the of ...

Ways to recover HTML elements that have been eliminated by jQuery's remove

$(document).ready(function() { $('#remove').click(function() { $('.test').remove(); }); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="test-wra ...

The value of the Post Form Request Object is currently set as 'object Object'

Just delving into the world of Node.js and I have come across several questions here on SO in relation to this topic. However, the issue I am facing is that the request body always shows as { 'object Object' : ''} Here is the server-si ...

Is there a way to automatically scroll to the last dynamically added div?

Within the chat.html file, I have included a div tag and implemented a script that dynamically adds rows to the div when a button is clicked. In another file named list.html, I have inserted an iframe tag with the src attribute pointing to chat.html. Howev ...

using any class as a function parameter in TypeScript

Looking for advice: I am new to TypeScript and have classes defined like the ones below: export declare class SampleOne extends Setting { getValue(): Promise<boolean>; setValue(value: boolean): Promise<void>; } And export declare class ...

Step-by-step guide on removing all elements except the last one using pure JavaScript, without relying on jQuery and utilizing document.querySelectorAll(".someClass"):

Here's my question: Is there a way to remove all elements except the last one with the same class name using vanilla JavaScript without jQuery? In jQuery, I can achieve this in one line like so: $('.someClass').not(':last(2)').re ...

Having trouble with variables while retrieving radio button values

Need Assistance with Radio Button Values! A big thank you to Shailendra Sharma for the support! I appreciate everyone's input as it has been a learning experience. Thank you all! My current issue revolves around: I am attempting to have the value o ...

Using a Do/While loop in combination with the setTimeout function to create an infinite loop

Having trouble with this script. The opacity transition works fine, but there seems to be an issue with the loop causing it to run indefinitely. My goal is to change the z-index once the opacity reaches 0. HTML <div class="ribbon_services_body" id="ri ...

AJAX: A breakdown of its functionality and operation

Similar Question: Understanding the Working of AJAX Important Note: This post is a community wiki Many people talk about AJAX for delivering dynamic content to users. Can you explain what AJAX is and how it functions? ...

Tips for validating a text field in React Material UI depending on the input from another text field

Currently, I am working with Material UI TextField and encountered an issue where I need to create a code that establishes a dependency between two textfields. For example, if I enter the number 4 in textfield one, then the number in textfield two should ...

Steps for linking a keypress to trigger a specific action

I need help creating a script that will redirect to a URL when a button is clicked. Below is the code I have developed. HTML : <a id="#next" href="example.com">↵</a> <a id="#previous" href="example.com">↳</a> JS : $(document ...

Modify the data within the JSON array using Github Actions

I currently have a JSON file with the following structure stored in the directory where my Github action is running - { "version":"1", "sampleArray":[ { "id":"1" } ], "secondArray":[ { "secondId":"2" } ...

Issue with IE7 when using JQuery to repopulate a <ul> unordered list: new elements showing up under previously hidden elements

Within this javascript snippet, I am utilizing the code below to clear out a list of countries within a <ul> element and then repopulate it (with a slight animation using jQuery's hide() function). The functionality works smoothly in Chrome and ...

Initiate an Ajax call to pre-fetch video content

I've been attempting to download a video from my own source and display a loading message while it's being downloaded. Once the download is complete, I want to hide the loading icon and have the video ready for playback. My issue lies in gettin ...

Step-by-step guide on incrementally counting localStorage items using jQuery

After spending an excessive amount of time on this project, I have hit a roadblock. Despite days of testing, I am unable to achieve my desired outcome. I am developing an image voting system that will track votes in localStorage. Since this is within Word ...

How can I create an HTML link that opens a drop-down menu with form functionality?

Feeling a bit perplexed here as I'm not entirely sure how to label this issue... If you're familiar with the Facebook interface, I'm trying to develop a feature similar to the "DOWNWARD ARROW" icon found next to the "comments" or "status" b ...