E-Notes PDF Unit-3 21052019110700AM
AI-enhanced title
Change Me by Entering Data
element with the content of the textbox that we enter. Browser Object * The Browser Object Model (BOM) allows JavaScript to “talk to" the browser, There are no official standards for the Browser Object Model (BOM). + The browser provides us with a hierarchy of objects which we can use to control and access various information about time, screen, page, elements on a page etc. * BOM objects allow to control the browser, e.g change current URL, access frames, do background requests to server with XMLHttpRequest etc. Functions like alert, confirm, prompt also belong BOM, they are provided by the browser. © The following details are some javaScript browser option: © History Object: Used for examining and moving between URLs stored in the browser's history. 3 | Dept: CE DWSI (3360705) Prof. Ravi G. ShrimaliDarshan Ince of of Dp Se -3 Object Models in JavaScript © Location Object: Contains information about the current URL. This object also provides the means to perform tasks such as loading a new page or reloading the current page. © Navigator Object: Contains information about the current browser. For example, you can determine the browser type and whether the browser has cookies enabled. © Screen Object: Specifies the physical characteristics of the device used to display the page, including page height, width, and color depth. © Window Object: Provides access to the browser's window so that you can perform tasks such as displaying message boxes. When working with pages that contain frames, the browser creates a window for the entire HTML document and another window for each frame. Note: The example of this object is same as Navigator Object below or Window Object (Refer page No. 17) Navigator Object The navigator object contains information about the browser. It is useful for customizing your JavaScript based on the user's browser and what they have enabled on that browser. Remember all browsers are different and handle JavaScript differently. For example, the user might not have cookies enabled, but has JavaScript enabled. Properties: appCodeName: Returns the code name of the browser. appName: Returns the name of the browser. appVersion: Returns the version information of the browser. cookieEnabled: Determines whether cookies are enabled in the browser. platform: Returns for which platform the browser is compiled userAgent: Returns the user-agent header sent by the browser to the server. Methods: © javaEnabled(): Specifies whether or not the browser has Java enabled. © taint€nabled(): Specifies whether the browser has data tainting enabled. Example: Output: Mozilla Netscape 0000 4 | Dept: CE DWSI (3360705) Prof. Ravi G. ShrimaliDarshan Ince of of Dp Se -3 Object Models in JavaScript 5.0 (Windows NT 6.2; WOW64) AppleWebkit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36 true win32 The String Objects A string literal is zero or more characters enclosed in single or double quotation marks. A string literal has a primary (primitive) data type of string. A String object is created by using the new Operator, and has a data type of Object. The escape character (\) can also be used to insert other special characters in a string. The Special characters that can be added to a text string with the backslash sign: single quote(\'), double quote(\"), backslash(\\), new line(\n), tab(\t), backspace(\b),etc. Syntax: var val = new String(string); Properties © constructor: Returns the function that created the String object's prototype © length: Returns the length of a string. © prototype: Allows you to add properties and methods to an object. Methods length: Returns the number of characters in a string, © indexOf(): Returns the position of the first found occurrence of a specified value in a string. © lastIndexOf(): Returns the position of the last found occurrence of a specified value in a string, © match(): Searches a string for a match against a regular expression, and returns the matches. © substr(): Extracts a part of a string from a start position through a number of characters. ° ° ° substring(): Extracts a part of a string between two specified positions. toLowerCase(): Converts a string to lowercase letters. toUpperCase(): Converts a string to uppercase letters. © trim(): Removes whitespace from both ends of a string. © valueOf{): Returns the primitive value of a String object. © split(): Splits a string into an array of substrings. Example: The above script remove extra whitespace from both sides of a string 5 | Dept: CE DWSI (3360705) Prof. Ravi G. ShrimalimH i arshan -3 Object Models in JavaScript Ince of of Dp Se Understanding built-in object (JavaScript Native Objects) * All programming languages have built-in objects that create the essential functionality of the language. Built-in objects are the foundation of the language in which you write custom code that powers custom functionality based on your imagination. ‘JavaScript has several built-in or native objects. These objects are accessible anywhere in your program and will work the same way in any browser running in any operating system. The below is the list of all important JavaScript Native Objects: JavaScript Number Object JavaScript Boolean Object JavaScript String Object JavaScript Array Object JavaScript Date Objec JavaScript Math Object e0000 User defined object * JavaScript is an Object based Programming language. Objects are composed of attributes. If an attribute contains a function, it is considered to be a method of the object otherwise, the attribute is considered a property. + Alluser-defined objects and bui in objects are descendants of an object called Object. ‘The new Operator: © The new operator is used to create an instance of an object. Example: var employee = new Object(); The Object) Constructor: © A constructor is a function that creates and initializes an object. JavaScript provides a special constructor function called Object() to build the object. The return value of the Object() constructor is assigned to a variable. The with Keyword: © The with keyword is used for referencing an object's properties or methods, © The object specified as an argument to with becomes the default object for the duration of the block that follows. The properties and methods for the object can be used without naming the object. Syntax: with (object}{ properties used without the object name and dot 6 | Dept: CE DWSI (3360705) Prof. Ravi G. ShrimaliDarshan Ince of of Dp Se -3 Object Models in JavaScript Example: