What are different Navigator methods available?

The Navigator object provides several methods to interact with the browser and detect client capabilities. Here are the main Navigator methods available in JavaScript:

Navigator Methods Overview

Method Description Browser Support
javaEnabled() Checks if Java is enabled in the browser All modern browsers
cookieEnabled Property that indicates if cookies are enabled All modern browsers
sendBeacon() Sends data to a server asynchronously Modern browsers
vibrate() Causes device vibration (mobile devices) Mobile browsers
geolocation Provides access to location services Modern browsers

Example: Using javaEnabled()

<script>
if (navigator.javaEnabled()) {
    console.log("Java is enabled in this browser");
} else {
    console.log("Java is not enabled in this browser");
}

// Check if cookies are enabled
console.log("Cookies enabled: " + navigator.cookieEnabled);
</script>
Java is not enabled in this browser
Cookies enabled: true

Example: Using sendBeacon()

<script>
// Send analytics data when page unloads
window.addEventListener('beforeunload', function() {
    const data = JSON.stringify({
        page: '/current-page',
        time: Date.now()
    });
    
    if (navigator.sendBeacon) {
        navigator.sendBeacon('/analytics', data);
        console.log("Analytics data sent using sendBeacon");
    }
});

// Check if sendBeacon is supported
console.log("sendBeacon supported: " + !!navigator.sendBeacon);
</script>
sendBeacon supported: true

Example: Using Vibration API

<script>
function testVibration() {
    if (navigator.vibrate) {
        // Vibrate for 200ms
        navigator.vibrate(200);
        console.log("Vibration triggered");
    } else {
        console.log("Vibration not supported");
    }
}

// Test vibration support
console.log("Vibration supported: " + !!navigator.vibrate);
testVibration();
</script>
Vibration supported: false
Vibration not supported

Legacy Methods (Deprecated)

Some older Navigator methods are now deprecated or removed:

  • taintEnabled() - Related to data tainting security model (removed)
  • plugins.refresh() - Refreshed plugin list (Netscape-specific, obsolete)
  • preference() - Set browser preferences (Netscape-specific, removed for security)

Conclusion

Modern Navigator methods like javaEnabled(), sendBeacon(), and vibrate() provide useful browser capabilities. Always check for method support before using them, as availability varies across browsers and devices.

Updated on: 2026-03-15T23:18:59+05:30

272 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements