FAQ about scripting server

1. Can JavaScript be run on the server?

Ans:

Many Web servers support JavaScript as a server side scripting language. In this case, JavaScript can be executed on the server and not on client’s browser. JavaScript (Jscript under IIS) is allowed to access server resources. If server side JavaScript is embedded in an HTML page then following tag definition should be used.

<script language=”JavaScript” runat=”server”>

</script>

2. How can you declare array in JavaScript?

Ans:

JavaScript has built in Array object, there are two ways for declaring an array:

  1. var arr = new Array( array_length );

arr[ 0 ] = “one”;

….

Arr[array_length - 1 ] = “somevalue”;

  1. var arr = new Array( “one”, “two”, “three” );

3. How can client’s system date be obtained using JavaScript?

Ans:

JavaScript has built in Date object for this. Following code will print current system date as dd/mm/yyyy

<script type=”JavaScript”>

var d = new Date()

document.write(d.getDate())

document.write(“/”)

document.write(d.getMonth() + 1)

document.write(“/”)

document.write(d.getFullYear())

</script>

4. How can you open a new browser window?

Ans:

You can open a new browser window using the window.open(url, window name, attributes) method of JavaScript. Note that you can also open a hyperlink in a new window simply using HTML as:

<a href =www.yahoo.com target=”_blank”>

5. Using JavaScript how can you determine client’s browser name and version?

Ans:JavaScript has navigator object to reference browser’s property. Browser’s name can be obtained using navigator.appName and its version can be obtained using navigator.appVersion.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>