SlideShare a Scribd company logo
1 of 6
Download to read offline
Lecture6
This lecture is a continuation of previous lecture. In the previous lecture, we studied
about following window objects
– screen object.
– images object
– links object
– history object
– location object.


This lecture we will study about last window object which is navigator object.

Due to so many browsers available, there is a problem that arises of browser
compatability. Browser compatability means, a CSS or Javascript code works perfectly in
one browser doesnot seem to render the same effect on other browser. This creates a
real headache for developers.

Every developer should make sure that web pages developed by him should work
perfectly across all browsers Or he can display a message suggesting the user to
upgrade his browser.

To display a message for the user, developer should be able to determine what sort of
browser is being used by user? This is where navigator objects come for help.

Actually there are 2 ways to determine if our code will work in user browser, Two ways
are

1. Checking browser by feature
2. Using Navigator object.

Checking browser by feature

Lets take an example, if you have 3 guys in front of you, and you need to determine
which country each guy belong to. You can do that by looking at the features of each
guy.
For example: We have 2 guys, an american, chinese and south african

if (skin color == white)
{
       type = american and chinse.
       If (eyes = small)
             type = chinese;
       else
             type = american;

}
else
       type = south african;
The above code can determine if a guy is an american or chinese or south african.

We determine the user browser, by checking the properties. For example, document.all
property is supported only by IE 4.0 and higher and not by netscape browser.

if (document.all)
{
       browser= “IE”;
       version = “4.0”;
}

But the above statement is true for IE 4.0, IE 5.0 and IE 6.0 but false for all Netscape
browser.

There is one property which is not supported by IE 4.0 and it is window.clipboardData.
Property window.clipborardata returns false on IE 4.0 browser but returns true on IE 5.0
and IE 6.0

if (document.all)
{
       browser= “IE”;
       version = “4.0”;

      if (window.clipboardata)
             version = “5.0”;
}



Similarly, document.layers property is only supported by Netscape browser 4.0 and
higher and not by IE browsers.

if (document.layers)
{
       browser = “NN”;
       version = “4.0”;
}

Property document.layers return false for IE browser, but returns true for all Netscape
browser. To check further about the version number, we use property window.sidebar,
which returns true for version 6.0 and returns false for version 4.0.

if (document.layers)
{
       browser = “NN”;
       version = “4.0”;
       if (window.sidebar)
             version = “6.0 +”;
}


So, the complete code is

<html>
<body>

<script>
var browser = "Unknown";
var version = "0";

// NN4+
if (document.layers)
{
       browser = "NN";
       version = "4.0";

     if (window.sidebar)
     {
            version = "6+";
     }
}
else if (document.all)
{
       browser = "IE";
       version = "4";

     if (window.clipboardData)
     {
            browser = "IE"
            version = "5+"
     }

}
document.write(browser + " " + version);

</script>

</body>
</html>

Using Navigator Object

Lets focus on the problem of finding the nationality. One way of finding nationality of a
guy is by looking at his features. Another method can be by just looking at his passport.
Each guy must have a passport and by looking inside passport we can find his
nationality.
But there is one problem with this approach. Passport can be illegaly made.

Similarly,We can use navigator object to know the type of browser being used by the
user. But some browsers that are not popular, disguise themselves as IE or NN.

Remember that navigaor object is a property of window object.

navigator.appName – this property returns the model of browser i.e. IE or NN etc.
navigator.userAgent – this property returns lot of information such as the browser
version, operating system, and browser model.

Code below finds the browser name, version.

<html>
<head>
<script language="JavaScript" type="text/JavaScript">

function getBrowserName()
{
  var lsBrowser = navigator.appName;
  if (lsBrowser.indexOf("Microsoft") >= 0)
  {
     lsBrowser = "MSIE";
  }
  else if (lsBrowser.indexOf("Netscape") >= 0)
  {
     lsBrowser = "NETSCAPE";
  }
  else
  {
     lsBrowser = "UNKNOWN";
  }
  return lsBrowser;
}
function getOS()
{
  var userPlat = "unknown";
  var navInfo = navigator.userAgent;
  if ((navInfo.indexOf("windows NT") != -1)
      || (navInfo.indexOf("windows 95") != -1 )
      || (navInfo.indexOf("windows 98") != -1 )
      || (navInfo.indexOf("WinNT") != -1 )
      || (navInfo.indexOf("Win95") != -1 )
      || (navInfo.indexOf("Win98") != -1 ))
  {
     userPlat = "Win32";
  }
  else if(navInfo.indexOf("Win16") != -1)
  {
userPlat = "Win16";
    }
    else if(navInfo.indexOf("Macintosh") != -1)
    {
      userPlat = "PPC";
    }
    else if(navInfo.indexOf("68K") != -1)
    {
      userPlat = "68K";
    }
    return userPlat;
}
function getBrowserVersion()
{
  var findIndex;
  var browserVersion = 0;
  var browser = getBrowserName();
  if (browser == "MSIE")
  {
  browserVersion = navigator.userAgent;
  findIndex = browserVersion.indexOf(browser) + 5;
  browserVersion = parseInt(browserVersion.substring(findIndex,findIndex + 1));

    }
    else
    {
      browserVersion = parseInt(navigator.appVersion.substring(0,1));
    }
    return browserVersion;
}

</script>
</head>
<body>
<script language="JavaScript" type="text/JavaScript">

var userOS = getOS();
var browserName = getBrowserName();
var browserVersion = getBrowserVersion();
if (browserVersion < 4 || browserName == "UNKNOWN" || userOS == "Win16")
{
   document.write("<h2>Sorry this browser version is not supported</h2>")
}
else if (browserName == "NETSCAPE")
{
   location.replace("NetscapePage.htm");
}
else
{
location.replace("MSIEPage.htm");
}

</script>
<noscript>
  <h2>This website requires a browser supporting scripting</h2>
</noscript>
</body>
</html>

The problem is that less known browsers disguise themselves as IE or NN but donot
support full functionality of IE or NN. So this method of finding type of browser is not
used. 1st metod is more popular.

More Related Content

What's hot

Google chrome presentation
Google chrome presentationGoogle chrome presentation
Google chrome presentationreza jalaluddin
 
Cross-Platform Desktop Apps with JavaScript
Cross-Platform Desktop Apps with JavaScriptCross-Platform Desktop Apps with JavaScript
Cross-Platform Desktop Apps with JavaScriptBlagoja Evkoski
 
HTML5 - The 2012 of the Web
HTML5 - The 2012 of the WebHTML5 - The 2012 of the Web
HTML5 - The 2012 of the WebRobert Nyman
 
Cookie & Session In ASP.NET
Cookie & Session In ASP.NETCookie & Session In ASP.NET
Cookie & Session In ASP.NETShingalaKrupa
 
Introduction to Jquery
Introduction to JqueryIntroduction to Jquery
Introduction to JqueryAmzad Hossain
 
Christmas Trees Made with HTML CSS and JS
Christmas Trees Made with HTML CSS and JSChristmas Trees Made with HTML CSS and JS
Christmas Trees Made with HTML CSS and JSNiamh Foley
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsasync_io
 
Php Sessoins N Cookies
Php Sessoins N CookiesPhp Sessoins N Cookies
Php Sessoins N Cookiesmussawir20
 
Chrome DevTools Introduction 2020 Web Developers Guide
Chrome DevTools Introduction 2020 Web Developers GuideChrome DevTools Introduction 2020 Web Developers Guide
Chrome DevTools Introduction 2020 Web Developers GuideLaurence Svekis ✔
 
Local SQLite Database with Node for beginners
Local SQLite Database with Node for beginnersLocal SQLite Database with Node for beginners
Local SQLite Database with Node for beginnersLaurence Svekis ✔
 
Web Cookies
Web CookiesWeb Cookies
Web Cookiesapwebco
 
Mocks, Proxies, and Transpilation as Development Strategies for Web Development
Mocks, Proxies, and Transpilation as Development Strategies for Web DevelopmentMocks, Proxies, and Transpilation as Development Strategies for Web Development
Mocks, Proxies, and Transpilation as Development Strategies for Web DevelopmentESUG
 
OSML and OpenSocial 0.9
OSML and OpenSocial 0.9OSML and OpenSocial 0.9
OSML and OpenSocial 0.9MySpaceDevTeam
 

What's hot (20)

Introduction to php web programming - sessions and cookies
Introduction to php   web programming - sessions and cookiesIntroduction to php   web programming - sessions and cookies
Introduction to php web programming - sessions and cookies
 
Php session
Php sessionPhp session
Php session
 
FuncUnit
FuncUnitFuncUnit
FuncUnit
 
Php sessions
Php sessionsPhp sessions
Php sessions
 
Php cookies
Php cookiesPhp cookies
Php cookies
 
Google chrome presentation
Google chrome presentationGoogle chrome presentation
Google chrome presentation
 
Cross-Platform Desktop Apps with JavaScript
Cross-Platform Desktop Apps with JavaScriptCross-Platform Desktop Apps with JavaScript
Cross-Platform Desktop Apps with JavaScript
 
HTML5 - The 2012 of the Web
HTML5 - The 2012 of the WebHTML5 - The 2012 of the Web
HTML5 - The 2012 of the Web
 
Cookie & Session In ASP.NET
Cookie & Session In ASP.NETCookie & Session In ASP.NET
Cookie & Session In ASP.NET
 
java Cookies
java Cookiesjava Cookies
java Cookies
 
Introduction to Jquery
Introduction to JqueryIntroduction to Jquery
Introduction to Jquery
 
Christmas Trees Made with HTML CSS and JS
Christmas Trees Made with HTML CSS and JSChristmas Trees Made with HTML CSS and JS
Christmas Trees Made with HTML CSS and JS
 
Practical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.jsPractical Use of MongoDB for Node.js
Practical Use of MongoDB for Node.js
 
Php Sessoins N Cookies
Php Sessoins N CookiesPhp Sessoins N Cookies
Php Sessoins N Cookies
 
Chrome DevTools Introduction 2020 Web Developers Guide
Chrome DevTools Introduction 2020 Web Developers GuideChrome DevTools Introduction 2020 Web Developers Guide
Chrome DevTools Introduction 2020 Web Developers Guide
 
Local SQLite Database with Node for beginners
Local SQLite Database with Node for beginnersLocal SQLite Database with Node for beginners
Local SQLite Database with Node for beginners
 
Web Cookies
Web CookiesWeb Cookies
Web Cookies
 
Bobcat Exchange Program
Bobcat Exchange ProgramBobcat Exchange Program
Bobcat Exchange Program
 
Mocks, Proxies, and Transpilation as Development Strategies for Web Development
Mocks, Proxies, and Transpilation as Development Strategies for Web DevelopmentMocks, Proxies, and Transpilation as Development Strategies for Web Development
Mocks, Proxies, and Transpilation as Development Strategies for Web Development
 
OSML and OpenSocial 0.9
OSML and OpenSocial 0.9OSML and OpenSocial 0.9
OSML and OpenSocial 0.9
 

Viewers also liked

The Second America
The Second AmericaThe Second America
The Second AmericaJohn Hoyte
 
Lecture8 digitaltoanalogconversion
Lecture8 digitaltoanalogconversionLecture8 digitaltoanalogconversion
Lecture8 digitaltoanalogconversionH K
 
Ch03
Ch03Ch03
Ch03H K
 
Pollock Expresionismo Abstracto
Pollock Expresionismo  AbstractoPollock Expresionismo  Abstracto
Pollock Expresionismo AbstractoNeyva
 
Week32
Week32Week32
Week32H K
 
Lecture4 isoosi
Lecture4 isoosiLecture4 isoosi
Lecture4 isoosiH K
 
Ip protocol
Ip protocolIp protocol
Ip protocolH K
 
Tribute To Dr.King
Tribute To Dr.KingTribute To Dr.King
Tribute To Dr.KingJohn Hoyte
 
Css 1
Css 1Css 1
Css 1H K
 
Reggaeton origin
Reggaeton originReggaeton origin
Reggaeton originJohn Hoyte
 
Java script browser objects 1
Java script browser objects 1Java script browser objects 1
Java script browser objects 1H K
 
Lecture3layered archi
Lecture3layered archiLecture3layered archi
Lecture3layered archiH K
 
What Do They Have in Common?
What Do They Have in Common?What Do They Have in Common?
What Do They Have in Common?John Hoyte
 
Lecture7 encodingmodulation
Lecture7 encodingmodulationLecture7 encodingmodulation
Lecture7 encodingmodulationH K
 
Culture & Diversity It Exists All Around Our World
Culture & Diversity It Exists All Around Our WorldCulture & Diversity It Exists All Around Our World
Culture & Diversity It Exists All Around Our WorldJohn Hoyte
 
Html basics 9 meta background
Html basics 9 meta backgroundHtml basics 9 meta background
Html basics 9 meta backgroundH K
 
Pollock Expresionismo Abstracto
Pollock Expresionismo AbstractoPollock Expresionismo Abstracto
Pollock Expresionismo AbstractoNeyva
 
Week31
Week31Week31
Week31H K
 

Viewers also liked (18)

The Second America
The Second AmericaThe Second America
The Second America
 
Lecture8 digitaltoanalogconversion
Lecture8 digitaltoanalogconversionLecture8 digitaltoanalogconversion
Lecture8 digitaltoanalogconversion
 
Ch03
Ch03Ch03
Ch03
 
Pollock Expresionismo Abstracto
Pollock Expresionismo  AbstractoPollock Expresionismo  Abstracto
Pollock Expresionismo Abstracto
 
Week32
Week32Week32
Week32
 
Lecture4 isoosi
Lecture4 isoosiLecture4 isoosi
Lecture4 isoosi
 
Ip protocol
Ip protocolIp protocol
Ip protocol
 
Tribute To Dr.King
Tribute To Dr.KingTribute To Dr.King
Tribute To Dr.King
 
Css 1
Css 1Css 1
Css 1
 
Reggaeton origin
Reggaeton originReggaeton origin
Reggaeton origin
 
Java script browser objects 1
Java script browser objects 1Java script browser objects 1
Java script browser objects 1
 
Lecture3layered archi
Lecture3layered archiLecture3layered archi
Lecture3layered archi
 
What Do They Have in Common?
What Do They Have in Common?What Do They Have in Common?
What Do They Have in Common?
 
Lecture7 encodingmodulation
Lecture7 encodingmodulationLecture7 encodingmodulation
Lecture7 encodingmodulation
 
Culture & Diversity It Exists All Around Our World
Culture & Diversity It Exists All Around Our WorldCulture & Diversity It Exists All Around Our World
Culture & Diversity It Exists All Around Our World
 
Html basics 9 meta background
Html basics 9 meta backgroundHtml basics 9 meta background
Html basics 9 meta background
 
Pollock Expresionismo Abstracto
Pollock Expresionismo AbstractoPollock Expresionismo Abstracto
Pollock Expresionismo Abstracto
 
Week31
Week31Week31
Week31
 

Similar to Java script browser objects 2

Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)Spike Brehm
 
WebAPIs & Apps - Mozilla London
WebAPIs & Apps - Mozilla LondonWebAPIs & Apps - Mozilla London
WebAPIs & Apps - Mozilla LondonRobert Nyman
 
Web APIs & Apps - Mozilla
Web APIs & Apps - MozillaWeb APIs & Apps - Mozilla
Web APIs & Apps - MozillaRobert Nyman
 
FINHTML5 - Breaking the mobile web
FINHTML5 - Breaking the mobile webFINHTML5 - Breaking the mobile web
FINHTML5 - Breaking the mobile webMaximiliano Firtman
 
Mozilla Web Apps - Super-VanJS
Mozilla Web Apps - Super-VanJSMozilla Web Apps - Super-VanJS
Mozilla Web Apps - Super-VanJSRobert Nyman
 
(In)Security Implication in the JS Universe
(In)Security Implication in the JS Universe(In)Security Implication in the JS Universe
(In)Security Implication in the JS UniverseStefano Di Paola
 
JavaScript Misunderstood
JavaScript MisunderstoodJavaScript Misunderstood
JavaScript MisunderstoodBhavya Siddappa
 
AFUP Lorraine - Symfony Webpack Encore
AFUP Lorraine - Symfony Webpack EncoreAFUP Lorraine - Symfony Webpack Encore
AFUP Lorraine - Symfony Webpack EncoreEngineor
 
Firefox OS - The platform you deserve - Athens App Days - 2013-11-27
Firefox OS - The platform you deserve - Athens App Days - 2013-11-27Firefox OS - The platform you deserve - Athens App Days - 2013-11-27
Firefox OS - The platform you deserve - Athens App Days - 2013-11-27Frédéric Harper
 
Firefox OS learnings & visions, WebAPIs - budapest.mobile
Firefox OS learnings & visions, WebAPIs - budapest.mobileFirefox OS learnings & visions, WebAPIs - budapest.mobile
Firefox OS learnings & visions, WebAPIs - budapest.mobileRobert Nyman
 
Honeynet Project Workshop 2014 - Thug: a low-interaction honeyclient
Honeynet Project Workshop 2014 - Thug: a low-interaction honeyclientHoneynet Project Workshop 2014 - Thug: a low-interaction honeyclient
Honeynet Project Workshop 2014 - Thug: a low-interaction honeyclientAngelo Dell'Aera
 
Building high performance web apps.
Building high performance web apps.Building high performance web apps.
Building high performance web apps.Arshak Movsisyan
 
Web APIs – expand what the Web can do
Web APIs – expand what the Web can doWeb APIs – expand what the Web can do
Web APIs – expand what the Web can doCarsten Sandtner
 
Compatibility Detector Tool of Chrome extensions
Compatibility Detector Tool of Chrome extensionsCompatibility Detector Tool of Chrome extensions
Compatibility Detector Tool of Chrome extensionsKai Cui
 
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09Frédéric Harper
 
BlackBerry DevCon 2011 - PhoneGap and WebWorks
BlackBerry DevCon 2011 - PhoneGap and WebWorksBlackBerry DevCon 2011 - PhoneGap and WebWorks
BlackBerry DevCon 2011 - PhoneGap and WebWorksmwbrooks
 
How to make Ajax Libraries work for you
How to make Ajax Libraries work for youHow to make Ajax Libraries work for you
How to make Ajax Libraries work for youSimon Willison
 

Similar to Java script browser objects 2 (20)

Pushing the Web: Interesting things to Know
Pushing the Web: Interesting things to KnowPushing the Web: Interesting things to Know
Pushing the Web: Interesting things to Know
 
Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)Building Isomorphic Apps (JSConf.Asia 2014)
Building Isomorphic Apps (JSConf.Asia 2014)
 
Html5 Overview
Html5 OverviewHtml5 Overview
Html5 Overview
 
WebAPIs & Apps - Mozilla London
WebAPIs & Apps - Mozilla LondonWebAPIs & Apps - Mozilla London
WebAPIs & Apps - Mozilla London
 
Web APIs & Apps - Mozilla
Web APIs & Apps - MozillaWeb APIs & Apps - Mozilla
Web APIs & Apps - Mozilla
 
FINHTML5 - Breaking the mobile web
FINHTML5 - Breaking the mobile webFINHTML5 - Breaking the mobile web
FINHTML5 - Breaking the mobile web
 
Mozilla Web Apps - Super-VanJS
Mozilla Web Apps - Super-VanJSMozilla Web Apps - Super-VanJS
Mozilla Web Apps - Super-VanJS
 
(In)Security Implication in the JS Universe
(In)Security Implication in the JS Universe(In)Security Implication in the JS Universe
(In)Security Implication in the JS Universe
 
JavaScript Misunderstood
JavaScript MisunderstoodJavaScript Misunderstood
JavaScript Misunderstood
 
AFUP Lorraine - Symfony Webpack Encore
AFUP Lorraine - Symfony Webpack EncoreAFUP Lorraine - Symfony Webpack Encore
AFUP Lorraine - Symfony Webpack Encore
 
Firefox OS - The platform you deserve - Athens App Days - 2013-11-27
Firefox OS - The platform you deserve - Athens App Days - 2013-11-27Firefox OS - The platform you deserve - Athens App Days - 2013-11-27
Firefox OS - The platform you deserve - Athens App Days - 2013-11-27
 
Firefox OS learnings & visions, WebAPIs - budapest.mobile
Firefox OS learnings & visions, WebAPIs - budapest.mobileFirefox OS learnings & visions, WebAPIs - budapest.mobile
Firefox OS learnings & visions, WebAPIs - budapest.mobile
 
Honeynet Project Workshop 2014 - Thug: a low-interaction honeyclient
Honeynet Project Workshop 2014 - Thug: a low-interaction honeyclientHoneynet Project Workshop 2014 - Thug: a low-interaction honeyclient
Honeynet Project Workshop 2014 - Thug: a low-interaction honeyclient
 
Building high performance web apps.
Building high performance web apps.Building high performance web apps.
Building high performance web apps.
 
End-to-end testing with geb
End-to-end testing with gebEnd-to-end testing with geb
End-to-end testing with geb
 
Web APIs – expand what the Web can do
Web APIs – expand what the Web can doWeb APIs – expand what the Web can do
Web APIs – expand what the Web can do
 
Compatibility Detector Tool of Chrome extensions
Compatibility Detector Tool of Chrome extensionsCompatibility Detector Tool of Chrome extensions
Compatibility Detector Tool of Chrome extensions
 
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09
Firefox OS, une plateforme à découvrir - IO Saglac - 2014-09-09
 
BlackBerry DevCon 2011 - PhoneGap and WebWorks
BlackBerry DevCon 2011 - PhoneGap and WebWorksBlackBerry DevCon 2011 - PhoneGap and WebWorks
BlackBerry DevCon 2011 - PhoneGap and WebWorks
 
How to make Ajax Libraries work for you
How to make Ajax Libraries work for youHow to make Ajax Libraries work for you
How to make Ajax Libraries work for you
 

More from H K

Assignment4
Assignment4Assignment4
Assignment4H K
 
Assignment3
Assignment3Assignment3
Assignment3H K
 
Induction
InductionInduction
InductionH K
 
Solution3
Solution3Solution3
Solution3H K
 
Solution2
Solution2Solution2
Solution2H K
 
Mid-
Mid-Mid-
Mid-H K
 
Assignment4
Assignment4Assignment4
Assignment4H K
 
Assignment4
Assignment4Assignment4
Assignment4H K
 
Dm assignment3
Dm assignment3Dm assignment3
Dm assignment3H K
 
Proof
ProofProof
ProofH K
 
Resolution
ResolutionResolution
ResolutionH K
 
Assignment description
Assignment descriptionAssignment description
Assignment descriptionH K
 
Dm assignment2
Dm assignment2Dm assignment2
Dm assignment2H K
 
Set
SetSet
SetH K
 
Dm assignment1
Dm assignment1Dm assignment1
Dm assignment1H K
 
Logic
LogicLogic
LogicH K
 
Introduction
IntroductionIntroduction
IntroductionH K
 
Assignment 2 sol
Assignment 2 solAssignment 2 sol
Assignment 2 solH K
 
Assignment sw solution
Assignment sw solutionAssignment sw solution
Assignment sw solutionH K
 
Violinphoenix
ViolinphoenixViolinphoenix
ViolinphoenixH K
 

More from H K (20)

Assignment4
Assignment4Assignment4
Assignment4
 
Assignment3
Assignment3Assignment3
Assignment3
 
Induction
InductionInduction
Induction
 
Solution3
Solution3Solution3
Solution3
 
Solution2
Solution2Solution2
Solution2
 
Mid-
Mid-Mid-
Mid-
 
Assignment4
Assignment4Assignment4
Assignment4
 
Assignment4
Assignment4Assignment4
Assignment4
 
Dm assignment3
Dm assignment3Dm assignment3
Dm assignment3
 
Proof
ProofProof
Proof
 
Resolution
ResolutionResolution
Resolution
 
Assignment description
Assignment descriptionAssignment description
Assignment description
 
Dm assignment2
Dm assignment2Dm assignment2
Dm assignment2
 
Set
SetSet
Set
 
Dm assignment1
Dm assignment1Dm assignment1
Dm assignment1
 
Logic
LogicLogic
Logic
 
Introduction
IntroductionIntroduction
Introduction
 
Assignment 2 sol
Assignment 2 solAssignment 2 sol
Assignment 2 sol
 
Assignment sw solution
Assignment sw solutionAssignment sw solution
Assignment sw solution
 
Violinphoenix
ViolinphoenixViolinphoenix
Violinphoenix
 

Recently uploaded

Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 

Recently uploaded (20)

Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 

Java script browser objects 2

  • 1. Lecture6 This lecture is a continuation of previous lecture. In the previous lecture, we studied about following window objects – screen object. – images object – links object – history object – location object. This lecture we will study about last window object which is navigator object. Due to so many browsers available, there is a problem that arises of browser compatability. Browser compatability means, a CSS or Javascript code works perfectly in one browser doesnot seem to render the same effect on other browser. This creates a real headache for developers. Every developer should make sure that web pages developed by him should work perfectly across all browsers Or he can display a message suggesting the user to upgrade his browser. To display a message for the user, developer should be able to determine what sort of browser is being used by user? This is where navigator objects come for help. Actually there are 2 ways to determine if our code will work in user browser, Two ways are 1. Checking browser by feature 2. Using Navigator object. Checking browser by feature Lets take an example, if you have 3 guys in front of you, and you need to determine which country each guy belong to. You can do that by looking at the features of each guy. For example: We have 2 guys, an american, chinese and south african if (skin color == white) { type = american and chinse. If (eyes = small) type = chinese; else type = american; } else type = south african;
  • 2. The above code can determine if a guy is an american or chinese or south african. We determine the user browser, by checking the properties. For example, document.all property is supported only by IE 4.0 and higher and not by netscape browser. if (document.all) { browser= “IE”; version = “4.0”; } But the above statement is true for IE 4.0, IE 5.0 and IE 6.0 but false for all Netscape browser. There is one property which is not supported by IE 4.0 and it is window.clipboardData. Property window.clipborardata returns false on IE 4.0 browser but returns true on IE 5.0 and IE 6.0 if (document.all) { browser= “IE”; version = “4.0”; if (window.clipboardata) version = “5.0”; } Similarly, document.layers property is only supported by Netscape browser 4.0 and higher and not by IE browsers. if (document.layers) { browser = “NN”; version = “4.0”; } Property document.layers return false for IE browser, but returns true for all Netscape browser. To check further about the version number, we use property window.sidebar, which returns true for version 6.0 and returns false for version 4.0. if (document.layers) { browser = “NN”; version = “4.0”; if (window.sidebar) version = “6.0 +”;
  • 3. } So, the complete code is <html> <body> <script> var browser = "Unknown"; var version = "0"; // NN4+ if (document.layers) { browser = "NN"; version = "4.0"; if (window.sidebar) { version = "6+"; } } else if (document.all) { browser = "IE"; version = "4"; if (window.clipboardData) { browser = "IE" version = "5+" } } document.write(browser + " " + version); </script> </body> </html> Using Navigator Object Lets focus on the problem of finding the nationality. One way of finding nationality of a guy is by looking at his features. Another method can be by just looking at his passport. Each guy must have a passport and by looking inside passport we can find his nationality.
  • 4. But there is one problem with this approach. Passport can be illegaly made. Similarly,We can use navigator object to know the type of browser being used by the user. But some browsers that are not popular, disguise themselves as IE or NN. Remember that navigaor object is a property of window object. navigator.appName – this property returns the model of browser i.e. IE or NN etc. navigator.userAgent – this property returns lot of information such as the browser version, operating system, and browser model. Code below finds the browser name, version. <html> <head> <script language="JavaScript" type="text/JavaScript"> function getBrowserName() { var lsBrowser = navigator.appName; if (lsBrowser.indexOf("Microsoft") >= 0) { lsBrowser = "MSIE"; } else if (lsBrowser.indexOf("Netscape") >= 0) { lsBrowser = "NETSCAPE"; } else { lsBrowser = "UNKNOWN"; } return lsBrowser; } function getOS() { var userPlat = "unknown"; var navInfo = navigator.userAgent; if ((navInfo.indexOf("windows NT") != -1) || (navInfo.indexOf("windows 95") != -1 ) || (navInfo.indexOf("windows 98") != -1 ) || (navInfo.indexOf("WinNT") != -1 ) || (navInfo.indexOf("Win95") != -1 ) || (navInfo.indexOf("Win98") != -1 )) { userPlat = "Win32"; } else if(navInfo.indexOf("Win16") != -1) {
  • 5. userPlat = "Win16"; } else if(navInfo.indexOf("Macintosh") != -1) { userPlat = "PPC"; } else if(navInfo.indexOf("68K") != -1) { userPlat = "68K"; } return userPlat; } function getBrowserVersion() { var findIndex; var browserVersion = 0; var browser = getBrowserName(); if (browser == "MSIE") { browserVersion = navigator.userAgent; findIndex = browserVersion.indexOf(browser) + 5; browserVersion = parseInt(browserVersion.substring(findIndex,findIndex + 1)); } else { browserVersion = parseInt(navigator.appVersion.substring(0,1)); } return browserVersion; } </script> </head> <body> <script language="JavaScript" type="text/JavaScript"> var userOS = getOS(); var browserName = getBrowserName(); var browserVersion = getBrowserVersion(); if (browserVersion < 4 || browserName == "UNKNOWN" || userOS == "Win16") { document.write("<h2>Sorry this browser version is not supported</h2>") } else if (browserName == "NETSCAPE") { location.replace("NetscapePage.htm"); } else {
  • 6. location.replace("MSIEPage.htm"); } </script> <noscript> <h2>This website requires a browser supporting scripting</h2> </noscript> </body> </html> The problem is that less known browsers disguise themselves as IE or NN but donot support full functionality of IE or NN. So this method of finding type of browser is not used. 1st metod is more popular.