CSS Question Bank(Unit Test02)
Q1. Describe regular expression. Explain search () method used in regular expression with suitable
example(4M)
Answer: Regular Expression:
A regular expression is very similar to a mathematical expression, except a
regular expression tells the browser how to manipulate text rather than numbers
by using special symbols as operators.
Search() method:
str.search() method takes a regular expression/pattern as argument and search
for the specified regular expression in the string. This method returns the index
where the match found.
Example:
<html>
<body>
<script>
function myFunction() {
// input string
var str = "Good Morning!";
// searching string with modifier i
var n = str.search(/Morning/i);
document.write(n + '<br>');
// searching string without modifier i
var n = str.search(/Morning/);
document.write(n);
myFunction();
</script>
</body>
</html>
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
Q2. List ways of protecting your web page and describe any one of them.(4M)
Ways of protecting Web Page:
1)Hiding your source code
2)Disabling the right MouseButton
3) Hiding JavaScript
4) Concealing E-mail address.
1) Hiding your source code
The source code for your web page—including your JavaScript—is stored in the
cache, the part of computer memory where the browser stores web pages that
were requested by the visitor. A sophisticated visitor can access the cache and
thereby gain access to the web page source code.
However, you can place obstacles in the way of a potential peeker. First, you can
disable use of the right mouse button on your site so the visitor can't access the
View Source menu option on the context menu. This hides both your HTML code
and your JavaScript from the visitor.
Nevertheless, the visitor can still use the View menu's Source option to display
your source code. In addition, you can store your JavaScript on your web server
instead of building it into your web page. The browser calls the JavaScript from
the web server when it is needed by your web page.
Using this method, the JavaScript isn't visible to the visitor, even if the visitor
views the source code for the web page.
2)Disabling the right MouseButton
The following example shows you how to disable the visitor's right mouse button
while the browser displays your web page. All the action occurs in the JavaScript
that is defined in the <head> tag of the web page.
The JavaScript begins by defining the BreakInDetected() function. This function
is called any time the visitor clicks the right mouse button while the web page is
displayed. It displays a security violation message in a dialog box whenever a
visitor clicks the right mouse button
The BreakInDetected() function is called if the visitor clicks any button other
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
than the left mouse button.
3) Hiding JavaScript
You can hide your JavaScript from a visitor by storing it in an external fi le on
your web server. The external fi le should have the .js fi le extension. The browser
then calls the external file whenever the browser encounters a JavaScript element
in the web page. If you look at the source code for the web page, you'll see
reference to the external .js fi le, but you won't see the source code for the
JavaScript.
The next example shows how to create and use an external JavaScript file. First
you must tell the browser that the content of the JavaScript is located in an
external
file on the web server rather than built into the web page. You do this by assigning
the fi le name that contains the JavaScripts to the src attribute of the <script>
tag, as shown here:
<script src="MyJavaScripts.js"
language="Javascript" type="text/javascript">
4) Concealing E-mail address:
Many of us have endured spam at some point and have probably blamed every
merchant we ever patronized for selling our e-mail address to spammers. While
e-mail addresses are commodities, it's likely that we ourselves are the culprits
who invited spammers to steal our e-mail addresses.
Here's what happens: Some spammers create programs called bots that surf the
Net looking for e-mail addresses that are embedded into web pages, such as those
placed there by developers to enable visitors to contact them. The bots then strip
these e-mail addresses from the web page and store them for use in a spam attack.
This technique places developers between a rock and a hard place. If they place
their e-mail addresses on the web page, they might get slammed by spammers. If
they don't display their e-mail addresses, visitors will not be able to get in touch
with the developers.
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
Q3. Explain text rollover with suitable example.(2M)
Answer: You create a rollover for text by using the onmouseover attribute of the tag, which is the
anchor tag. You assign the action to the onmouseover attribute the same way as you do with <img>
tag.
<HTML>
<head></head>
<Body>
<textarea rows=”2″ cols=”50″ name=”rollovertext” onmouseover=”this.value=’What is
rollover?'”
onmouseout=”this.value=’Rollover means a webpage changes when the user moves his or
her mouse over an object on the page'”></textarea>
</body>
</html>
Q4: Explain open() method of window object with syntax and example.(4M)
Answer: The open() method of window object is used to open a new window and loads the
document specified by a given URL.
MyWindow = window.open()
The open() method returns a reference to the new window, which is assigned to
the MyWindow variable. You then use this reference any time that you want to
do something with the window while your JavaScript runs.
A window has many properties, such as its width, height, content, and name—to
mention a few. You set these attributes when you create the window by passing
them as parameters to the open() method:
• The first parameter is the full or relative URL of the web page that will appear
in the new window.
• The second parameter is the name that you assign to the window.
• The third parameter is a string that contains the style of the window.
We want to open a new window that has a height and a width of 250 pixels and
displays an advertisement that is an image. All other styles are turned off.
Syntax:
MyWindow = window.open(‘webpage1.html’, 'myAdWin', 'status=0, toolbar=0,
location=0, menubar=0, directories=0, resizable=0, height=250, width=250')
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
Example:
<html >
<head>
<title>Open New Window</title>
<script >
function OpenNewWindow() {
MyWindow = window.open(‘webpage1.html’, 'myAdWin', 'status=0, toolbar=0,
location=0,
menubar=0, directories=0, resizable=0, height=250, width=250')
</script>
</head>
<body>
<FORM action=" " method="post">
<INPUT name="OpenWindow" value="Open Window" type="button"
onclick="OpenNewWindow()"/>
</FORM>
</body>
</html>
Q5: Create a slideshow with the group of three images, also simulate next and previous transition
between slides in your Java Script.
Answer:
<html>
<head>
<script>
pics = new Array('1.jpg' , '2.jpg' , '3.jpg');
count = 0;
function slideshow(status)
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
if
(document.images)
count = count + status;
if (count > (pics.length - 1))
count = 0;
if (count < 0)
count = pics.length - 1;
documet.imag1.src = pics[count];
</script>
</head>
<body>
<img src="1.jpg" width="200" name="img1">
<br>
<input type="button" value="Next" onclick="slideshow(1)">
<input type="button" value="Back" onclick="slideshow(-1)">
</body>
</html>
Q6 : Write a Java script to modify the status bar using on MouseOver and on MouseOut with links.
When the user moves his mouse over the links, it will display “MSBTE” in the status bar. When the
user moves his mouse away from the link the status bar will display nothing.(4M)
Answer:
<html>
<head>
<title>JavaScript Status Bar</title></head>
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
<body>
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
<a href="
https://msbte.org.in/" onMouseOver="window.status='MSBTE';return true"
onMouseOut="window.status='';return true">
MSBTE
</a>
</body>
</html>
Q7: Describe, how to read cookie value and write a cookie value. Explain with
example.
Answer:
Web Browsers and Servers use HTTP protocol to communicate and HTTP is a
stateless protocol. But for a commercial website, it is required to maintain
session information among different pages. For example, one user registration
ends after completing many pages. But how to maintain users' session
information across all the web pages.
Cookies are a plain text data record of 5 variable-length fields −
Expires − The date the cookie will expire. If this is blank, the cookie will
expire when the visitor quits the browser.
Domain − The domain name of your site.
Path − The path to the directory or web page that set the cookie. This
may be blank if you want to retrieve the cookie from any directory or
page.
Secure − If this field contains the word "secure", then the cookie may
only be retrieved with a secure server. If this field is blank, no such
restriction exists.
Name=Value − Cookies are set and retrieved in the form of key-value
Pairs
Storing Cookies
The simplest way to create a cookie is to assign a string value to the
document.cookie object, which looks like this.
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
document.cookie = "key1 = value1;key2 = value2;expires = date";
Here the expires attribute is optional. If you provide this attribute with a valid
date or time, then the cookie will expire on a given date or time and thereafter,
the cookies' value will not be accessible.
<html>
<head>
<script type = "text/javascript">
<!--
function WriteCookie()
if( document.myform.customer.value == "" ) {
alert("Enter some value!");
return;
cookievalue = escape(document.myform.customer.value) + ";";
document.cookie="name=" + cookievalue;
document.write ("Setting Cookies : " + "name=" + cookievalue );
//-->
</script>
</head>
<body>
<form name = "myform" action = "">
Enter name: <input type = "text" name = "customer"/>
<input type = "button" value = "Set Cookie" onclick = "WriteCookie();"/>
</form>
</body>
</html>
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
9. Write a javascript to create a pull-down menu with three options [Google, MSBTE, Yahoo] once
the user will select one of the options then user will be redirected to that site.
Answer:
<html>
<head>
<title>HTML Form</title>
<script language="javascript" type="text/javascript">
function getPage(choice)
page=choice.options[choice.selectedIndex].value;
if(page != "")
window.location=page;
</script>
</head>
<body>
<form name="myform" action="" method="post">
Select Your Favourite Website:
<select name="MenuChoice" onchange="getPage(this)">
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
<option
value="https://www.google.com">Google</option>
<option
value="https://www.msbte.org.in">MSBTE</option>
<option
value="https://www.yahoo.com">Yahoo</option>
</form>
</body>
</html>
Q10: State any two properties and methods of location object.(2M)
Properties of location object:
1. hash 2. host 3. hostname 4. href 5. Origin
2. 6. pathname 7. port 8. protocol 9. Search
3. Methods of location object: 1. assign( ) 2. reload( ) 3. replace( )
Q11.Explain the term bowser location and history in details
Q12.Explain the block diagram of browser
Q13.Write a java script that will replace following specified value with another value in string(use
replace method)
String =”I will fail”
Replace fail by pass
Q14.Write steps to create a frame with example.
Q15:Explain Frame work of JavaScript
Q16. Write a JavaScript program that will display current date in DD/MM/YYYY format.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
<meta
name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var d=new Date();
var currentDate=d.getDate()+'/'+(d.getMonth()+1)+'/'+d.getFullYear()
document.write(currentDate)
</script>
</body>
</html>
Q17. Write HTML script that will display dropdown list containing options such as Red, Green, Blue
and Yellow. Write a JavaScript program such that when the user selects any options. It will change
the background colour of webpage.
Answer:
<html>
<body>
<label for="color">Choose a Background Color:</label>
<select name="color" id="color" class="color" onchange="changeColor()">
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
<option value="yellow">Yellow</option>
</select>
<script type="text/javascript">
function changeColor() {
var color = document.getElementById("color").value;
switch(color){
case "green":
document.body.style.backgroundColor = "green";
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
break;
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
case "red":
document.body.style.backgroundColor = "red";
break;
case "blue":
document.body.style.backgroundColor = "blue";
break;
case "yellow":
document.body.style.backgroundColor = "yellow";
break;
default:
document.body.style.backgroundColor = "white";
break;
</script>
</body>
</html>
Q18: Develop a JavaScript program to create Rotating Banner Ads.[4M]
Answer:
<html >
<head>
<title>Banner Ads</title>
<script>
Banners = new Array('1.jpg','2.jpg','3.jpg');
CurrentBanner = 0;
function DisplayBanners()
if (document.images);
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
CurrentBanner++;
if (CurrentBanner == Banners.length)
CurrentBanner = 0;
document.RotateBanner.src= Banners[CurrentBanner];
setTimeout("DisplayBanners()",1000);
</script>
</head>
<body onload="DisplayBanners()" >
<center>
<img src="1.jpg" width="400"
height="75" name="RotateBanner" />
</center>
</body>
</html>
Q19 Describe Quantifiers with the help of example.
The frequency or position of bracketed character sequences and single characters can be denoted by
a special character. Each special character has a specific connotation. The +, *, ?, and $ flags all
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
follow a character
sequence.
Example:
<html>
<body>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction()
var str = "100, 1000 or 10000?";
var patt1 = /\d{3,4}/g;
var result = str.match(patt1);
document.getElementById("demo").innerHTML = result;
</script>
</body>
</html>
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
Q20: Describe how to link
banner advertisement to URL with example.
The banner advertisement is the hallmark of every commercial web page. It is typically
positioned near the top of the web page, and its purpose is to get the visitor's attention by
doing all sorts of clever things.
To get additional information, the visitor is expected to click the banner so that a new web
page opens. You can link a banner advertisement to a web page by inserting a hyperlink
into your web page that calls a JavaScript function rather than the URL of a web page. The
JavaScript then determines the URL that is associated with the current banner and loads the
web page that is associated with the URL.
Example:
<html>
<head>
<title>Link Banner Ads</title>
<script language="Javascript" type="text/javascript">
Banners = new Array('1.jpg','2.jpg','3.jpg')
BannerLink = new Array(
'google.com/','vpt.edu.in/', 'msbte.org.in/');
CurrentBanner = 0;
NumOfBanners = Banners.length;
function LinkBanner()
document.location.href =
"http://www." + BannerLink[CurrentBanner];
function DisplayBanners() {
if (document.images) {
CurrentBanner++
if (CurrentBanner == NumOfBanners) {
CurrentBanner = 0
document.RotateBanner.src= Banners[CurrentBanner]
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material
setTimeout("DisplayBanners()",1000)
</script>
</head>
<body onload="DisplayBanners()" >
<center>
<a href="javascript: LinkBanner()"><img src="1.jpg"
width="400" height="75" name="RotateBanner" /></a>
</center>
</body> </html>
Free Study Material Buy Ty Diploma Buy Sy Diploma Whatsapp Group for Study Material