Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

simple JavaScript navigator.appName script I cant get to work?

Featured Replies

Hi So I'm just trying to creat a simple script which finds the browser a visitor is using, replaces the name and then writes the result to the page:

 

Heres the basic script:

<head>
<script type="text/javascript">
		var browser = navigator.appName;
                       var browserName = getName();
function getName()
		{


			if ( browser == netscape)
			{
			document.write("Firefox");
			}
			else if ( browser == Microsoft Internet Explorer )
                               {
                               document.write("Internet Explorer");
                               }
			else 
			{
			document.write("a web browser");
			}
		}
</script>
</head>
<body>
<p>
You are using <script type=(text/javascript)> browserName </script>.
</p>
</body>

 

Let me know if I have missed somthing you might need to solve this really rather simple script, simple if you arent a complete newbie to javascript!! :rolleyes:

as a newbie, are you missing a ; along the way?

  • Author

Well spotted thanks, but thats not what is causing the problem is it?

I though the semi colons were just good practice not required?

Not tested but try

 

<head>
<script type="text/javascript">
                       var browser = navigator.appName;
                       var browserName = getName();
                       var display = document.getElementById('browser');
function getName()
                       {


                               if ( browser == 'netscape')
                               {
                               display.innerHTML("You are using Firefox");
                               }
                               else if ( browser == 'Microsoft Internet Explorer' )
                               {
                               display.innerHTML("You are using Internet Explorer");
                               }
                               else 
                               {
                               display.innerHTML("You are using a web browser");
                               }
                       }
</script>
</head>
<body onLoad="getName();">
<p id="browser">
</p>
</body>

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.