Practical No 15
Practical No 15
Objective
Develop a webpage for implementing Status bars and web page protection.
Resource Used
- Computer with a text editor (e.g., Notepad++, Visual Studio Code)
- Web browser (e.g., Chrome, Firefox)
Theory
JavaScript gives you the ability to modify the status bar. For example it can be useful to
display information about a link, when the user moves his mouse over it or you can display
a small amount of information about the page the user is on in the status bar. You can also
trick people into clicking a link, so be careful how you use it. If you play too many tricks on
your visitors, they might not come back.
<html>
<head>
</body>
</html>
onLoad tells the browser that as soon as your page finished loading, it will display in your current window’s
status bar (window.status) the message “Welcome!”. The return true is necessary because without, it won’t
work.
<html>
<head>
<title>JavaScript Status Bar</title></head>
<body>
<a href="http://www.htmlcenter.com" onMouseOver="window.status='HTMLcenter';
return true" onMouseOut="window.status='';return true"> HTMLcenter
</a>
</body>
</html>
Our second script listening shows how to modify the status bar using onMouseOver and
onMouseOut with links. When the user moves his mouse over the link, it will display
“HTMLcenter” in the status bar. When he moves his mouse away from the link the status
bar will display nothing.
You could also have another message displayed in the status bar, when the user moves his
mouse cursor away from the link. You have to change the onMouseOut statement in the
link to for example: onMouseOut=”window.status=’You moved your cursor away from the
link.’;return true”.
Program :
Example
<html>
<head>
<script language="JavaScript"> function function2() {
alert("This image is copyrighted")
}
</script>
</head>
<body oncontextmenu="function2()">
<p>Right click in the image.</p>
<img oncontextmenu="function2()" src="http://www.java2s.com/style/logo.png"
alt="www.java2s.com"
width="99" height="76">
</body>
</html>
If you want to disable the context menu, add the following code to the <body>:
oncontextmenu="function2(); return false;"
<html>
<head>
<title>Scrolling Text</title>
<script language="JavaScript"> var scrollPos = 0
var maxScroll = 100 var blanks = ""
Output :
Conclusion