CSS 22519 Master Notes
CSS 22519 Master Notes
<!DOCTYPE html>
<html>
<head>
<title>HTML in Script Tag</title>
</head>
<body>
<script>
document.write('<h1>This is HTML content inside a script tag</h1>');
document.write('<p>You can add any HTML here.</p>');
</script>
</body>
</html>
prompt() Method:
The prompt() method displays a dialog box with a message, an input field for the user to enter
data, and buttons to submit or cancel. It returns the text entered by the user as a string, or null
if the user cancels the dialog.
• message (optional): A string that specifies the message to be displayed in the dialog
box.
• default (optional): A string that specifies the default value displayed in the input field.
alert() Method:
The alert() method displays an alert dialog box with a message and an OK button. It is
commonly used to display informational messages or to alert users of errors.
• message: A string that specifies the message to be displayed in the alert dialog box.
confirm() Method:
The confirm() method displays a confirmation dialog box with a message, OK, and Cancel
buttons. It returns true if the user clicks OK and false if the user clicks Cancel.
let result = confirm("Are you sure you want to delete this item?");
if (result) {
console.log("Item deleted.");
} else {
console.log("Deletion cancelled.");
}
• border: Specifies the border width around the table cells. It can be set to 1 for a visible
border or 0 for no border.
• cellpadding: Specifies the padding (space) between the cell content and cell borders.
• cellspacing: Specifies the spacing between cells.
•
<!DOCTYPE html>
<html lang="en">
<head>
<title>Simple Table Example</title>
</head>
<body>
<table border="1" cellpadding="5" cellspacing="0">
<caption>Monthly Expenses</caption>
<thead>
<tr>
<th>Category</th>
<th>Amount ($)</th>
</tr>
</thead>
<tbody>
<tr>
<td>Food</td>
<td>200</td>
</tr>
<tr>
<td>Transportation</td>
<td>100</td>
</tr>
</tbody>
</table>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Frameset Example</title>
</head>
<body>
<frameset cols="25%,*,25%">
<frame src="menu.html" name="menu">
<frame src="content.html" name="content">
<frame src="sidebar.html" name="sidebar">
</frameset>
</body>
</html>
5. Regular Expressions
Regular expressions (regex) in JavaScript are used for pattern matching within strings. They
allow you to search for and manipulate text based on specific criteria. A regular expression is
a pattern of characters.The pattern is used for searching and replacing characters in strings.
The RegExp Object is a regular expression with added Properties and Methods.
Creating Regular Expressions: You can create a regular expression in JavaScript using the
RegExp constructor or by using a regex literal.
Matching: You can use the test() method to check if a string matches a regex pattern, or
match() method to extract matches.
// Extract matches
console.log(str.match(regex)); // Output: ["Hello"]
Modifiers: You can add modifiers to a regex pattern to change its behavior, like case-
insensitive matching or global matching.
Character Classes: Character classes match any one of a set of characters. For example, \d
matches any digit character.
Quantifiers: Quantifiers specify how many instances of a character, group, or character class
must be present in the input for a match to be found.
Anchors: Anchors specify the position in the input string where a match must occur.
6. Cookies
Types of Cookies:
1. Session Cookies - These cookies are stored temporarily and are deleted when the browser
session ends. They are typically used to maintain session state, such as keeping a user logged
in while navigating between pages of a website. Session cookies are primarily used for
session management and do not contain any personally identifiable information.
2. Persistent Cookies - Unlike session cookies, persistent cookies are stored on the user's
device even after the browser session ends. They have an expiration date set in the future.
Persistent cookies are often used for purposes such as remembering user preferences, tracking
user behaviour for analytics, and delivering personalized content.
<html>
<head>
<script>
function writeCookie()
{
var d=new Date();
d.setTime(d.getTime()+(1000*60*60*24));
with(document.myform)
{
document.cookie="Name=" + person.value + ";expires="
+d.toGMTString();
}
}
function readCookie()
{
if(document.cookie=="") //document.cookie.length==0
document.write("cookies not found");
else
document.write(document.cookie);
}
</script>
</head>
<body>
<form name="myform" action="">
Enter your name:
<input type="text" name="person"><br>
<input type="Reset" value="Set C" type="button"
onclick="writeCookie()">
<input type="Reset" value="Get C" type="button"
onclick="readCookie()">
</form>
</body>
</html>
• 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 hide 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.
Disabling the Right Mouse Button
The preventDefault() method cancels the event if it is cancelable, meaning that the default
action that belongs to the event will not occur.
For example, this can be useful when:
<html>
<head>
<script>
window.onload = function(){
document.addEventListener("contextmenu", function(e)
{
e.preventDefault();
}, false);}
</script>
</head>
<body>
<h3>Right click on screen,Context Menu is disabled</h3>
</body>
</html>
Hiding Javascript
You can hide your JavaScript from a visitor by storing it in an external file on your web
server. The external file should have the .js file extension. The browser then calls the external
fi le 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 file, but you won't see
the source code for the JavaScript.
<html>
<head>
<script src="mycode.js" languages="javascript" type="text/javascript">
</script>
</head>
<body>
<h3> Right Click on screen, Context Menu is disabled</h3>
</body>
</html>
• 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.
• To conceal an e-mail address, you need to create strings that contain part of the
• e-mail address and then build a JavaScript that assembles those strings into the e-mail
address, which is then written to the web page.
<html >
<head>
<title>Conceal Email Address</title>
<script>
function CreateEmailAddress()
{
var x = 'abcxyz*c_o_m'
var y = 'mai'
var z = 'lto'
var s = '?subject=Customer Inquiry'
x = x.replace('&','@')
x = x.replace('*','.')
x = x.replace('_','')
x = x.replace('_','')
var b = y + z +':'+ x + s
window.location=b;
}
</script>
</head>
<body>
<input type="button" value="send" onclick="CreateEmailAddress()">
</body>
</html>
8. Rollover in Javascript.
Though HTML can be used to create rollovers, it can only perform simple actions. If you
wish to create more powerful rollovers, you need to use JavaScript. To create rollovers in
JavaScript, we need to create a JavaScript function and trigger them on onmouseover and
onmouseout.
<html>
<head>
<title>text rollovers</title>
</head>
<body>
<table border="1" width="100%">
<tbody>
<tr valign="top">
<td width="50%">
<a><img height="500" src="blue.png" width="900"
name="clr"></a>
</td>
<td>
<a onmouseover="document.clr.src='blue.png' ">
<b>
<u> Blue Color</u>
</b>
</a>
<br>
<a onmouseover="document.clr.src='red.png' ">
<b>
<u> Red Color</u>
</b>
</a>
<br>
<a onmouseover="document.clr.src='green.png' ">
<b>
<u> Green Color</u>
</b>
</a>
</td>
</tr>
</tbody>
</table>
</body>
</html>
<html>
<head>
<title>Link Banner Ads</title>
<script language="Javascript" type="text/javascript">
Banners = new Array('1.jpg','2.jpg','3.jpg')
10. Slideshow
<html>
<title>slideshow</title>
<body>
<h2 class="w3-center">Manual Slideshow</h2>
<div class="w3">
<img class="mySlides" src="y.jpg" style="width:50%">
<img class="mySlides" src="yy.jpg" style="width:50%">
<img class="mySlides" src="yyy.jpg" style="width:50%">
<img class="mySlides" src="yyyy.jpg" style="width:50%">
<script>
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n)
{
showDivs(slideIndex += n);
}
function showDivs(n)
{
var i;
var x = document.getElementsByClassName("mySlides");
if (n > x.length)
{
slideIndex = 1
}
if (n < 1)
{
slideIndex = x.length
}
for (i = 0; i < x.length; i++)
{
x[i].style.display = "none";
}
x[slideIndex-1].style.display = "block";
}
</script>
</body>
</html>