Showing posts with label JavaScript. Show all posts
Showing posts with label JavaScript. Show all posts

Monday, February 8, 2010

How do you assign object properties in JavaScript?

JavaScript window Object Properties

window.closed - indicates whether a window has been closed or not.

window.defaultstatus / window.status - specifies the default message / message displayed in the browser status bar.

window.frames[] - This array holds the array of frame objects of the window

window.name - Contains the name of the window object. (Windows opened by a script need to have a name)

window.opener - contains a reference of the parent window which opened it.

window.parent - contains a reference to the window object that contains the frame

window.screen - contains information about the screen on which the window is displayed like height, width, availHeight, availWidth and colorDepth.

window.self - A reference to the current window.

window.top - A reference to the top-level window when working with frames.

Methods GET vs. POST in HTML forms.

Encoding form data into URL is needed by the GET method. The form data is to be appeared within the message body , by the POST method. By specification, GET is used basically for retrieving data where as POST is used for data storing, data updating, ordering a product or even e-mailing.

JavaScript - Methods GET vs. POST in HTML forms

The GET method in the HTML forms passes the form values by setting the URL.

Eg: If you type the word ‘Hello’ in Google Search, it sets the following URL:

http://www.google.co.in/search?hl=en&q=hello&btnG=Search&meta=&aq=f&oq=

The POST method sends the data to the server without setting the URL:

Eg:
-----------------------------97891525516423
Content-Disposition: form-data; name="username"

aaaa
-----------------------------97891525516423
Content-Disposition: form-data; name="password"

bbbbb12345
-----------------------------97891525516423
Content-Disposition: form-data; name="submit"

Submit
-----------------------------97891525516423--

JavaScript - What does the EnableViewStateMac setting in an aspx page do? -

Opening Browser Windows using JavaScript

newWindowObj = window.open("URL", "WindowName", " EnableViewStateMac setting is a security measure in ASP.Net. It ensures the view state for a page not to tamper. To to so “ EnableViewStateMac=true “is used. ASP.net detects the change in the value of view state sent to the browser when Postback action takes place and raises an error – “Validation of view state MAC failed”.

JavaScript - What does the EnableViewStateMac setting in an aspx page do?

EnableViewStateMac is a security measure used by ASP.NET in order to ensure that the viewstate for a page has not been tampered with.

ASP.NET raises an error (Validation of viewstate MAC failed) if it detects that there has been a change in the value of viewstate that was sent to the browser.

JavaScript - What are windows object and navigator object in JavaScript? -

Windows object is top level object in Java script. It contains several other objects such as, document, history, location, name, menu bar etc., in itself. Window object is the global object for Java script that is written at client-side.

Information pertaining to the client browser and system is returned by the navigator object of JavaScript. Navigator object is the top level object for all users.

JavaScript - What are windows object and navigator object in JavaScript?

The details of the client browser can be obtained sing JavaScript. Details such as client name, version, codename and the platform can be obtained.
navigator.appName - Gives the name of the browser
navigator.appVersion - Gives the browser version
navigator.appCodeName - Gives the browser codename
navigator.platform - Gives the platform on which the browser is running
The JavaScript Window Object is the top level JavaScript object which corresponds to the web browser window.

feature, feature, feature ... ");
features - A comma separated list of features that allow you to customize the appearance of the window

How to detect the operating system on the client machine in JavaScript?

The navigator.appVersion string should be used to find the name of the operating system on the client machine. The following code snippet returns the appropriate Operating systems.

var OSName="Unknown OS";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="UNIX";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";

How to detect the operating system on the client machine in JavaScript?

navigator.platform returns the platform on which the browser is running< /P>

JavaScript vs. Jscript

JavaScript is a scripting language developed by Netscape Communications.
The Netscape Navigator interprets JavaScript embedded into Web pages.
JavaScript is used for developing web applications.
It is not dependent on Sun Microsystem's Java language.

JScript
Microsoft JScript is an open implementation of Netscape's JavaScript.
JScript is a scripting language designed to create active online content. ActiveX controls, Java programs, etc can be linked and automated in the web pages using JScript.

What is the difference between Client side JavaScript and Server side JavaScript.

Client side java script comprises the basic language and predefined objects which are relevant to running java script in a browser. The client side java script is embedded directly by in the HTML pages. This script is interpreted by the browser at run time.

Server side java script also resembles like client side java script. It has relevant java script which is to run in a server. The server side java scripts are deployed only after compilation.

What is the difference between Client side JavaScript and Server side tJavaScript?

Client-Side JavaScript (CSJS)
It is JavaScript that enables the enables web pages on browsers to run active online content.

Server-Side JavaScript (SSJS)
It is JavaScript that enables back-end access to databases, file systems, and servers

Where are cookies actually stored on the hard disk?

The storage of cookies on the hard disk depends on OS and the browser. The Netscape navigator on Windows, the file cookies.txt contains all the cookies. The path is :

c:\Program Files\Netscape\Users\username\cookies.txt

The Internet Explorer stores the cookies on a file by name username@website.txt is

c:\Windows\Cookies\username@Website.txt

JavaScript - Where are cookies actually stored on the hard disk?

This depends on the user's browser and OS.

In the case of Netscape on Windows OS, its stored in cookies.txt

In IE, each cookie is stored in a file and has is named as username@website.txt.

JavaScript - What is the difference between a web-garden and a web-farm? -

Web garden is a web hosting system. It is a setup of multi processors in single server.

Web farm is a web hosting system. It is a multi-server scenario.

What is the difference between a web-garden and a web-farm?

The term ‘Web Farm’ indicates a business that performs Web site hosting on multiple servers.

The term ‘Web Garden’ means a multi-processor machine

What is the difference between SessionState and ViewState?

The values of controls of a particular page of the client browser is persisted by ViewState at the time of post back operation is done. If the user requests another page, the data of previous page is no longer available.

The data of a particular server persists in the server by SessionState. The availability of the user data is up to the completion of a session or closure of the browser.

A ViewState is a state of a page within a browser wherein the values of controls persist when post back operation is done.
When another page is loaded, the previous page data is no longer available.

SessionState is the data of a user session and is maintained on the server side. This data available until user closes the browser or session time-outs.

How to Accessing Elements using javascript?

The elements of JavaScript are accessed by their names. By default the browser is accessed by the element ‘windows’ and the page by ‘document’. The corresponding element has user defined names for forms and its elements. For example

var passwd = windows.document.frmLogin.password.value;

assigns the value of the password field of the form fromLogin in the current document, where password is the name of the element and frmLogin is the name of the form. Like wise any form element is accessed.

How to Accessing Elements using javascript?

Following are some of the functions with which the elements can be retrieved:

getElementById()
getElementByName()
getElementByValue()
getElementByTag()

What is the difference between undefined value and null value?

Undefined value: A value that is not defined and has no keyword is known as undefined value. For example in the declaration, int number; the number has undefined value.

Null value: A value that is explicitly specified by the key word ‘null’ is known as null value. For example in the declaration, String str=null; the str has a null value. The keyword ‘null’ is used here.

null value has keyword called ‘null’. That is not the case with undefined.

typeof undefined variable or property returns undefined whereas
typeof null value returns object.

How to set the cursor to wait in JavaScript?

The cursor can set to wait in JavaScript by using the property ‘cursor’ property. The following example illustrates the usage.

window.document.body.style.cursor = "wait"; // sets the cursor shape to hour-glass.

How to set the cursor to wait in JavaScript?


A moue over this yellow patch will show you the wait cursor.


What is decodeURI(), encodeURI() in JavaScript?

To send the characters that can not be specified in a URL should be converted into their equivalent hex encoding. To perform this task the methods encodeURI() and decodeURI() are used.

For example, the following code snippet performs the encoding of URL:

What is decodeURI(), encodeURI() in JavaScript?

These functions are used to encode and decode the URIs.

Eg:
String: Career Ride

Operation: encodeURI()
Output: Career%20Ride

Operation: decodeURI()
Output: Career Ride

What is JavaScript?

JavaScript is a scripting language most often used for client-side web development.

What boolean operators does JavaScript support?

Answer
==
!=
<
>
<=
>=

Is a javascript script faster than an ASP script?

Answer
JSP is faster then ASP as the script is run on the client side. Only the computation is done on the server side.

What is == operator ?

Answer
The ‘==’ operator is a boolean comparison operator that returns true if the variables on its both sides are compared equal else it returns false.

What is negative infinity?

Answer
It’s a number that is obtained by dividing a negative number by zero. (in JSP)

What’s relationship between JavaScript and ECMAScript?

Answer
JavaScript is a scripting language most often used for client-side web development. It was the originating dialect of the ECMAScript standard. ECMAScript and LiveScript are other names for JavaScript. The current JavaScript that is supported in browsers is ECMAScript revision 3.

What does isNaN function do?

Answer
The isNaN function determines if the value is a number or not and depending upon the result, it returns true or false.

How to read and write a file using javascript?

There are two ways to do it:

1. Using JavaScript extensions (runs from JavaScript Editor), or

2. Using a web page and ActiveX objects (Internet Explorer only)

In JavaScript Extensions, you can use
fh = fopen(getScriptPath(), 0); to open a file

Using ActiveX objects, following should be included in your code to read a file:

var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.OpenTextFile("C:\\example.txt", 1, true);

How do you create a new object in JavaScript?

In order to generate dynamic content, JSP provides for creating, modifying and interacting with Java objects. The implicit objects like page, config, request, etc are called so because their availability in the in JSP page is automatic.

Also, along with using constructor functions (e.g. var mything = new myObject();), you can use Object Initializers to create objects in JSP.
E.g:
var myCar = {color:"white",wheels:4,engine:{cylinders:4,size:2.2}};

How to create arrays in JavaScript?

Although you can create the arrays using ‘new’ (var myArray = new myArray[10];), it is recommended that you create it in the following way: var myArray = [];

You don't need to tell Javascript how many items to size the Array for. Javascript automatically increases the size of the Array as needed.