Topic 6 CSS
Topic 6 CSS
Client Side Scripting Language 6-1 Menus, Navigation and Web Page Protection
Menus, Navigation
and Web Page Protection
Status bar is present at the bottom of browser window. We will use onMouseOver and onMouseOut events of
It enhances the readability of the text present on the a hyper link to display or manage the messages.
web page, when user scrolls over it. We can use window.status on OnMouseOver event to
change the status in the status bar. You can display a
6.1.1 Build Static Message
javascript status bar message whenever your users hover
We can build a static message which is displayed on
over your hyperlinks.
the status bar. This message remains permanently
present in the status bar. Java Script
<html>
Java Script <head>
<!DOCTYPE html> <title>JavaScript Status Bar</title></head>
<html> <body>
<body> <a href="../"
<script> onMouseOver="window.status='Welcome';return true"
window.status = "Welcome!! This is information onMouseOut="window.status='';return true">
in displayed in your status bar!!"; Hello, Click here and check the statusbar
</script> </a>
</body> </body>
</html> </html>
Output Output
(6 - 1)
Client Side Scripting Language 6-2 Menus, Navigation and Web Page Protection
Output
6.1.3 Moving the Message along the Status Bar
For moving the message in the status bar we need to
increment the current position of the text one character
ahead in a loop. This will give us the effect of moving
the text. This will be displayed by using the setInterval
function, which displays the moved text after some
milliseconds.
Following javascript illustrates this idea
Java Script
<html>
<head>
<title>Scrolling Text</title>
<script language="JavaScript">
6.2 Banner
var currentPosition = 0
6.2.1 Loading and Displaying Banner Advertisement
var targetPos = 100
var blanks = "" It is a typically rectangular advertisement placed on
function scroll_function(msg, milliseconds) { a Web site either above, below or on the sides of the
Web site's main content and is linked to the
window.setInterval("display('"+msg+"')", milliseconds)
advertiser's own Web site.
}
It is also referred as banner ad.
window.defaultStatus = blanks + msg banners in which it slides from one banner to another.
++currentPosition Prerequisite : In our example,
blanks += " "
(1) we have created four images and we named them as
if(currentPosition > targetPos)
banner1.jpg, banner2.jpg, banner3.jpg, and
{
banner4.jpg.
currentPosition = 0
blanks = "" (2) Save the images in the same folder as the HTML file
} which will be used to show the banners. These
} images can be created by using some graphics tools
</script> or image files can be downloaded from Internet.
</head>
<body onload="scroll_function
('This text is moving', 100)">
<p>Watch the text scroll at the
bottom of this window!</p>
</body></html>
Client Side Scripting Language 6-3 Menus, Navigation and Web Page Protection
JavaScript Document
<html>
<head>
<script language="Javascript">
MyBanners=new Array('banner1.jpg','banner2.jpg',
'banner3.jpg','banner4.jpg');
banner_count=0;
function DisplayBanners()
{
if (document.images)
{
banner_count++;
if (banner_count==MyBanners.length)
{
banner_count=0;
}
document.BannerChange.src=MyBanners[banner_count];
setTimeout("DisplayBanners()",2000);
}
}
</script>
<body onload="DisplayBanners()">
<center>
<h1> Displaying Banner </h1>
<img src="banner1.jpg" width="900" height="120" name="BannerChange"/>
</center>
</body>
</html>
Output
Client Side Scripting Language 6-4 Menus, Navigation and Web Page Protection
JavaScript Document
<html>
<head>
<script language="Javascript">
MyBanners=new Array('banner1.jpg','banner2.jpg','banner3.jpg','banner4.jpg');
MyBannerLinks=new Array('www.google.com/','www.gmail.com/','www.facebook.com/','www.wikipedia.com/')
banner_count=0;
function DisplayLinks()
{
document.location.href="http://"+MyBannerLinks[banner_count];
}
function DisplayBanners()
{
if (document.images)
{
banner_count++;
if (banner_count==MyBanners.length)
{
banner_count=0;
}
document.BannerChange.src=MyBanners[banner_count];
setTimeout("DisplayBanners()",2000);
}
}
</script>
<body onload="DisplayBanners()">
<center>
<h1> Displaying Banner </h1>
<a href="javascript: DisplayLinks()">
Client Side Scripting Language 6-5 Menus, Navigation and Web Page Protection
JavaScript Document
<!DOCTYPE html>
<head>
<script language="Javascript">
MySlides=new Array('slide1.jpg','slide2.jpg','slide3.jpg','slide4.jpg')
i=0
function DisplaySlides(SlideNumber)
{
i=i+SlideNumber;
if (i>MySlides.length-1)
{
i=0;
}
if (i<0)
{
i=MySlides.length-1;
}
document.SlideID.src=MySlides[i];
}
</script>
</head>
<body>
<img src="slide1.jpg" name="SlideID" width="200" height="200" />
<br/><br/>
<input type="button" value="Back" onclick="DisplaySlides(-1)">
<input type="button" value="Forward" onclick="DisplaySlides(1)">
</body>
</html>
Output
Client Side Scripting Language 6-7 Menus, Navigation and Web Page Protection
selectedIndex=0">
Script Explanation : In above JavaScript <form action="" name="Form1">
(1) An array named MySlides is created in which the <select name="MyMenu" onchange="Display(this)">
four image files act as four slides. <option>Books</option>
<option
(2) In <body> section, the image tag is used to place the value="Fiction.html">Fiction</option>
first slide. <option value="NonFiction.html">
Non Fiction</option>
(3) Then two buttons are placed – one for moving back
</select>
in slide show and anther is for moving forward in
</form>
slide show. For each transition(either forward or </body>
back the function DisplaySlides will be called by </html>
passing initial –1 or +1 value. Output
(4) DisplaySlides is a simple function in which the
index i of slide is incremented by one. When the
slide show reaches to maximum slide number it is
reset and the slide show is possible from beginning.
6.4 Menus
JavaScript Document
On clicking any of the choice in above document, you
<!DOCTYPE>
<html>
will be directed to corresponding HTML page.
<head>
6.4.2 Dynamically Changing the Menu
<title>Pull Down Menu</title>
<script language="Javascript"> Dynamically changing menu means the items present in
function Display(Ch) the menu are changing automatically. Following is a
{ Javascript example in which two menus are created –
MyPage = Ch.options[Ch.selectedIndex].value
one for category of students in the Class and other menu
if (MyPage != "")
{ is for displaying names of boys students or
window.location = MyPage names of girl students based on the selection. Thus
}
} other menu displaying appropriate names of students
</script> is a dynamic menu.
</head>
<body onload="document.Form1.MyMenu.
Client Side Scripting Language 6-8 Menus, Navigation and Web Page Protection
JavaScript
<!DOCTYPE html>
<html>
<head>
<title>Dynamically Changing Menu Options</title>
<script language="Javascript">
BoysList = new Array('Sunil','Aditya','Siddharth')
GirlsList = new Array('Archana','Sharda', 'Swati')
function DisplayStudents(Class)
{
// clearing current options
for(i=document.Form1.Students.options.length-1;i>0; i--)
{
document.Form1.Students.options.remove(i)
}
Category = Class.options[Class.selectedIndex].value
if (Category != "") //somethig is selected
{
if (Category == '1')
{
for (i=1; i<=BoysList.length;i++)
{
//displaying names of boys
document.Form1.Students.options[i] =new Option(BoysList[i-1])
}
}
if (Category == '2')
{
for (i=1; i<=GirlsList.length;i++)
{
//displaying names of girls
document.Form1.Students.options[i] = new Option(GirlsList[i-1])
}
}
}
}
</script>
</head>
<body onload="document.Form1.ClassList.selectedIndex=0">
<h2> Dynamically Changing Menu</h2>
<form name="Form1">
<select name="ClassList" onchange="DisplayStudents(this)">
<option value="0">Class</option>
<option value="1">Boys</option>
<option value="2">Girls</option>
</select>
<select name="Students">
Client Side Scripting Language 6-9 Menus, Navigation and Web Page Protection
<option value="0">Students</option>
</select>
</form>
</body>
</html>
Output
Just Select the category of students from ‘Class’ menu and dynamically the ‘Students’ menu will change.
For instance-just refer following screenshot