0% found this document useful (0 votes)
17 views

Quesion Bank UT-2 CSS(22519)

Uploaded by

snehamagade1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Quesion Bank UT-2 CSS(22519)

Uploaded by

snehamagade1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

BHARATI VIDYAPEETH COLLEGE OF ENGINEERING

(DIPLOMA)
QUESTION BANK (Answers)
Unit Test-II
Program: - Computer Engineering Group Program Code: - CO
Course Title: -Client-Side Scripting Language Semester: - Fifth
Course Abbe &Code: -CSS (22519) Scheme: I
*Kindly Note: All the question are taken from previous year question papers
Summer-22, Winter-23, Summer-23 that includes Chapter No. 4,5 and 6
as per the instruction of Subject Teacher.
--------------------------------------------------------------------------------------------------

 Summer – 2022
1. Unit IV: Cookies and Browser Data

1. Differentiate between session cookies and persistent cookies. (Q1(b))


Session cookies Persistent cookies
Session cookies are temporary and pe Persistent cookies are permanent and
expire when the browser is closed. remain on the device until a set
expiration date.
Session cookies are stored in memory Persistent cookies are stored on the
and not written to disk hard drive or device.
Session cookies work only in the currentpe Persistent cookies can be used in future
session sessions.
Example: Session cookies track items in Example: persistent cookies remember
a shopping cart language settings.

2. Design a webpage with inputs for username and password, and write the
JavaScript function for storing these values in cookies. (Q2(d))
<html>
<body>
<form >
Enter Username: <input type="text" id="uname"/><br/>
Enter Password: <input type="password" id="pwd"/><br/>
<input type="button" value="Submit" onclick="storeCookie()"/>
</form>
<script>
function storeCookie() {
var pwd = document.getElementById('pwd').value;

CREATED BY PRACHI
document.cookie = "Password: " + pwd + ";";
alert("Cookie Stored" + document.cookie);
}
</script>
</body>
</html>

3. Write a JavaScript program to create, read, update, and delete cookies. (Q3(a))
<html >
<head>
<title>Cookie Example</title>
<script>
function setCookie(value) {
document.cookie = "username=" + value;
}
function getCookie() {
alert(document.cookie);
}
function updateCookie(value) {
setCookie(value);
alert("Cookie updated to: " + value);
}
function deleteCookie() {
document.cookie = "username=";
}
function example() {
setCookie('Trisha_Jadhav');
getCookie();
updateCookie('Prachi_Jadhav');
getCookie();
deleteCookie();
getCookie();
}
</script>
</head>
<body>
<h1>Cookie Example</h1>

CREATED BY PRACHI
<button onclick="example()">Run Example</button>
</body>
</html>

4. Write a JavaScript program to change the contents of a window. (Q1(e))


<html>
<head>
<title>Changing Content of Window</title>
<script>
function OpenNewWindow(Ad)
{
MyWindow = window.open(Ad, 'myAdWin', 'status=0,toolbar=0, location=0,
menubar=0, directories=0,resizable=0, height=250, width=250')
}
</script>
</head>
<body>
<FORM>
<P>
<INPUT name="Website1" value="Website 1" type="button"
onclick="OpenNewWindow('www.google.co.in')"/>
<INPUT name=" Website2" value="Website 2" type="button"
onclick="OpenNewWindow('www.msbte.org.in')"/>
</P>
</FORM>
</body>
</html>

5. Write a JavaScript to open a new window with two frames. (Q6(a))


<html>
<head>
<script>
function openFrames() {
var newWindow = window.open('', 'newWindow',
'width=800,height=600');
newWindow.document.write(`
<frameset cols="50%,50%">
<frame src="css.jpg" name="frame1">
<frame src="ajp.jpg" name="frame2">
</frameset>

CREATED BY PRACHI
`);
newWindow.document.close();
}
</script>
</head>

<body>
<button onclick="openFrames()">Open New Window with Frames</button>
</body>
</html>

6. Write a JavaScript syntax to access elements of another child window. (Q1(g))


Syntax: window. open()

2. Unit V: Regular Expression, Rollover, and Frames


1. Write a JavaScript program to validate an email ID of the user using regular
expressions. (Q4(c))
<html>
<head>
<script>
function validateEmail() {
var email = "user@example.com";
var re = /^[a-zA-Z0-9._]+@[a-zA-Z0-9.-]+/;

if (re.test(email)) {
alert('Email format seems valid');
}
else {
alert('Invalid Email ID');
}
}
</script>
</head>
<body onload="validateEmail()">
</body>
</html>

2. State what a regular expression is and provide an example. (Q3(d))


 A regular expression is a sequence of characters that forms a search
pattern.

CREATED BY PRACHI
 A regular expression can be a single character, or a more complicated
pattern
 The JavaScript RegExp class represents regular expressions, and both
String and RegExp define methods.
 It uses regular expressions to perform pattern-matching and search-and-
replace functions

 Example:-
<html>
<head>
<script>
function Reg ()
{
var name="Prachi";
re=/[Pr]/;
if(re.test (name))
{
alert ('Found');
}
else
{
alert ('Not Found');
}
}
</script>
</head>
<body onload= "Reg ()" >
</body>
</html>

3. Write a JavaScript program to design an HTML page with book information


and use rollovers to display discount information. (Q4(d))
<html>
<body>
<table border="1">
<tr>
<td> Book </td>
<td> Price </td>

CREATED BY PRACHI
</tr>
<tr
onmouseover="document.getElementById('discount').innerHTML='Discount:
15%'">
<td> CSS </td>
<td> 230 </td>
</tr>
<tr
onmouseover="document.getElementById('discount').innerHTML='Discount:
10%'">
<td> AJP </td>
<td> 240 </td>
</tr>
<tr
onmouseover="document.getElementById('discount').innerHTML='Discount:
12%'">
<td> OSY </td>
<td> 260 </td>
</tr>
</table>
<p id="discount"></p>
</body>
</html>
3. Unit VI: Menus, Navigation, and Webpage Protection
1. Write a JavaScript program to link banner advertisements to different URLs.
(Q3(b))
<html>
<head>
<script>
var MyBanners = new Array('ajp.jpg','css.jpg');
var banner = 0;
var MyBannerLinks = new Array('https://bit.ly/ajp-book',
'https://bit.ly/css-guide');
function ShowLinks() {
document.location.href = MyBannerLinks[banner];
}
function ShowBanners() {
if (document.images) {
banner++;
if (banner == MyBanners.length) {
banner = 0;

CREATED BY PRACHI
}
document.ChangeBanner.src = MyBanners[banner];
setTimeout(ShowBanners, 3000);
}
}
</script>
</head>
<body onload="ShowBanners()">
<a href="javascript: ShowLinks()">
<img src="" width="500" height="500" name="ChangeBanner"/>
</a>
</body>
</html>

2. Write a javascript program to create a silde show with the group of six images,
also simulate the next and previous transition between slides in your javascript.
. (Q5(c))
<html>
<head>
<script>
img_array= new Array("pineapple.jpg","apple.jpg","strawberry.jpg",
"watermelon.jpg","orange.jpg","cherry.jpg")
img=0;
function DisplayImg(num)
{
img=img+num;
if(img>img_array.length-1)
{
img=0;
}
if(img<0)
{
img=img_array.length-1;
}
document.Slide.src=img_array[img];
}
</script>
<body>
<img src="book2.jfif" width="400" height="220" name="Slide"/>
<br></br>
<input type="button" value="Pervious" onclick="DisplayImg(-1)">
<input type="button" value="Next" onclick="DisplayImg(1)">
</body>
</html>

CREATED BY PRACHI
3. Write a JavaScript code to create an option list and display selected images in
a new window. (Q6(b))
<html>
<body>
<h2>Select an Image</h2>
<select id="image">
<option value="">--Choose an image--</option>
<option value="Red.jpg">Red Image</option>
<option value="Green.jpg">Green Image</option>
<option value="Blue.jpg">Blue Image</option>
</select>

<button onclick="showImage()">Show Image</button>


<script>
function showImage() {
var selectedValue = document.getElementById('image').value;
if (selectedValue)
{
var newWindow = window.open();
newWindow.document.write('<img src="' + selectedValue + '" >');
}
else
{
alert('Please select an image.');
}
}
</script>
</body>
</html>

4. List ways of protecting your webpage and describe any one of them. (Q4(e))
 Hiding your source code
 Disabling the right MouseButton
 Hiding JavaScript
 Concealing E-mail address.

• 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 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 file, but you won't see the source
code for the JavaScript.

CREATED BY PRACHI
• 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 file name that contains the JavaScripts to the src attribute of the
<script> tag.
Example:-

Webpage1.html:
<html>
<head>
<script src="code.js" language="Javascript" type="text/javascript">
</script>
<body>
<h3> Right click on screen, Context Menu is disabled</h3>
</body>
</html>

Code.js:
window.onload=function()
{
document.addEventListener("contextmenu",function(e)
{ e.preventDefault();}, false);
}

CREATED BY PRACHI
 Summer – 2023

1. Unit IV: Cookies and Browser Data

 Cookies
1. Explain how to create and read Persistent Cookies in JavaScript with an
example. (Q3(d))
Persistent cookies in JavaScript are those that remain stored on the user's
device after the browser session ends, allowing data to be retained even
after the browser is closed. Here's how you can create and read persistent
cookies in JavaScript.

1. Creating a cookie:
document.cookie = "user=Prachi; expires=Fri, 01 Jan 2025 00:00:00
UTC; path=/";

2. Reading a cookie:
function getCookie(name) {
var cookies = document.cookie.split("; ");
for (var cookie of cookies) {
const [key, value] = cookie.split("=");
if (key === name) return value;
}
return null;
}
document. write(getCookie("user")); // Outputs:Prachi

 Browser
1. Write the use of charCodeAt() and fromCharCode() method with syntax
and example. (Q2(d))

In JavaScript, charCodeAt() and String.fromCharCode() are useful for


working with character codes.

1. charCodeAt()
The charCodeAt() method returns the Unicode value (character code) of
the character at a specified index in a string.
Syntax: string.charCodeAt(index);

Example:
var str = "Hello";
var charCode = str.charCodeAt(0); // Get the character code of 'H'
document. write(charCode); // Output: 7

CREATED BY PRACHI
2. String.fromCharCode()
The String.fromCharCode() method converts Unicode values to characters.
Syntax: String.fromCharCode(num1, ..., numN);

Example:
var char = String.fromCharCode(72); // Convert Unicode 72 to 'H'
document. write(char); // Output: H

2. Write HTML code to design a form with two buttons START and
STOP. Implement timer functionality to display a real-time digital clock
using JavaScript. (Q5(b))
<html>
<head>
<title>Digital Clock</title>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
text-align: center;
margin-top: 100px;
font-size: 50px;
color: #333;
}
</style>
</head>
<body onload="setInterval(() => {
var date = new Date();
var time = (date.getHours() % 12 || 12) + ':' + ('0' + date.getMinutes()).slice(-2) + ':' +
('0' + date.getSeconds()).slice(-2) + ' ' + (date.getHours() >= 12 ? 'PM' : 'AM');
document.getElementById('clockDisplay').textContent = time;
}, 1000);">
<div id="clockDisplay"></div>
</body>
</html>

2. Unit V: Regular Expression, Rollover, and Frames

 Regular Expressions 
1. Explain test() and exec() method of the Regular Expression object with
an example. (Q4(a))

1. test() Method
The test() method checks whether a pattern exists in a given string.
It returns a Boolean value: true if the pattern is found, and otherwise false.

CREATED BY PRACHI
Syntax: regex.test(string);

Example:
var regex = /hello/;
var string = "hello world";
document.write(regex.test(string)); // Output: true

In this example, test() checks if the word "hello" is present in the


string.Since "hello" is found, it returns true.

2. exec() Method
The exec() method searches for a match in a specified string and returns an
array containing the matched text if found. If there’s no match, it returns
null. This method is particularly useful when you need more information
about the match, such as capturing groups.

Syntax: regex.exec(string);

Example:
var regex = /hello/;
var string = "hello world";
document. write(regex.exec(string)); // Output: ["hello"]

In this example, exec() finds the match "hello" in the string and returns an
array with "hello" as the first element.

 Frames
1. Write a script for creating a frame structure where clicking SPORT,
MUSIC, or DANCE buttons displays different web pages in separate
frames. (Q6(b))

 Rollover
1. Explain text and image rollover with a suitable example. (Q4(d))

CREATED BY PRACHI
Text rollover:
• You can create as many rollovers as you want on your web page.
• A clever rollover technique used by some developers is to enable a visitor to see
additional information about an item described in text by placing the mouse
cursor on the text.
• You create a rollover for text by using the onmouseover attribute of the <A>
tag, which is the anchor tag. You assign the action to the onmouseover attribute
the same way as you do with an <IMG> tag.
<html>
<body>
<TABLE width="100%" border="0">
<TBODY>
<TR>
<TD>
<a>
<IMG height="250" src="CSS.jpg"
width="200" border="0" name="cover">
</a>
</TD>
<TD>
<IMG height="1" src="" width="10">
</TD>
<TD>
<A onmouseover="document.cover.src='CSS.jpg'">
<B><U>Client Side Scripting</U></B>
</A>
<BR>
<A onmouseover="document.cover.src='OSY.jpg'">
<B><U>Operating System</U></B>
</A>
<BR>
<A onmouseover="document.cover.src='STE.jpg'">
<B><U>Software Testing</U></B>
</A>
</TD>
</TR>
</TBODY>
</TABLE>
</body>
</html>
Image Rollover:
• The onmouseover event by using the onmouseover attribute of an HTML tag that
defines the object on the web page and then assign to the onmouseover attribute

CREATED BY PRACHI
the action you want performed when the event occurs.
• The <IMG> tag defines the image object. The value assigned to the src attribute
of the <IMG> tag identifies the image itself. Whenever the onmouseover event
occurs, we need to change the value of the src attribute to identify the new
image.
<html>
<head>
<title> RollOver</title>
</head>
<body>
<IMG src="CSS.jpg" height="150" width="100" alt="no image"
onmouseover="src='OSY.jpg'"/>
</body>
</html>

3. Unit VI: Menus, Navigation, and Webpage Protection

 Status Bar
1. What is the Status bar, and how can you display a moving message on it
using JavaScript? (Q4(e))
<html>
<head>
<script>
msg="This is an example of scrolling message";
spacer="............ .............";
pos=0;
function ScrollMessage()
{
window.status=msg.substring(pos,msg.length)+spacer+msg.substring(0,pos);
pos++;
if(pos>msg.length)
pos=0;
window.setTimeout("ScrollMessage()",100);
}
ScrollMessage();
</script>
</head>
<body>
<p>Scrolling Message Example</p>
<p>Look at the status line at the bottom of the page</p>
</body>
</html>

CREATED BY PRACHI
 Banner
1. Explain how to create and display a Rotating Banner in JavaScript with
an example. (Q4(c))
<html>
<head>
<script>
MyBanners=new Array('CSS.jpg','CSS1.jpg','OSY.jpg','STE.jpg')
banner=0
function ShowBanners()
{
if (document.images)
{
banner++
if (banner==MyBanners.length)
{
banner=0}
document.ChangeBanner.src=MyBanners[banner]
setTimeout("ShowBanners()",5000)
}
}
</script>
<body onload="ShowBanners()">
<center>
<img src="banner1.jpg" width="400" height="800"
name="ChangeBanner"/>
</center>
</body>
</html>

 Slide Show
Write a JavaScript program to create a slideshow with transitions between six
images. (Q5(c))Answer will given above

CREATED BY PRACHI
 Menus
1. Write a JavaScript code to create a pull-down menu with options
[AICTE, DTE, MSBTE, GOOGLE] that redirects to the selected site.
(Q6(c))

<html>
<body>
Select a Website:
<select onchange="show(this)">
<option value="https://www.google.com">Google</option>
<option value="https://www.msbte.com">MSBTE</option>
<option value="https://www.yahoo.com">Yahoo</option>
</select>
<script>
function show(select)
{
window.location.href =select.value;
}
</script>
</body>
</html>

 Webpage Protection
1. List ways of protecting your webpage and describe any one of them.
(Q4(b)Answer will given above

-------------------------------------------------------------------------------------------------------

CREATED BY PRACHI
 Winter – 23

1. Unit IV: Cookies and Browser Data

 Cookies
1. State what a cookie is, explain its need, and state characteristics of
persistent cookies. (Q3(d))
A cookie is a small piece of data that is stored on a user's device
(such as a computer or smartphone) by a web browser when they visit
a website. Cookies are used to remember information about the user’s
interaction with the site, such as login credentials, preferences, or
tracking information.
Example : document.cookie = "username=Prachi; expires=Fri, 01 Dec
2024 12:00:00 UTC; path=/";

 Need for Cookies


1. Manage Sessions: Keep users logged in as they navigate a website.
2. Personalize Experiences: Remember preferences (e.g., language,
themes).
3. Track User Activity: Collect data for analytics or targeted ads.
4. Store Information Between Requests: Save things like shopping carts or
form data.
5. Improve Security: Help with user authentication and prevent attacks.

 Characteristics of Persistent Cookies


A persistent cookie is a cookie that remains on the user's device
even after the browser is closed and reopened. It is stored with an
expiration date and will only be deleted when that date is reached
or when the user manually removes it.
1. Expiration Date: Persistent cookies have a set expiration date using the
expires or max-age attribute.
2. Storage Duration: They remain on the user's device until the expiration
date is reached, even after the browser is closed.
3. Path and Domain: You can specify the path and domain where the cookie
is accessible.
4. Secure: The Secure flag ensures cookies are only sent over HTTPS
connections.
5. HttpOnly: The HttpOnly flag prevents JavaScript access to the cookie,
enhancing security against XSS attacks.
6. Manual Deletion: Persistent cookies can be manually deleted by the user
or when the expiration date is passed

CREATED BY PRACHI
 Browser
1. Describe the “navigator” object in JavaScript and describe the methods
used to display browser name and version. (Q2(b))
The navigator object in JavaScript is used to access the information of
the user's browser. ---- Using the 'navigator' object, you can get the
browser version and name and check whether the cookie is enabled in
the browser.
- The 'navigator' object is a property of the window object.
- The navigator object can be accessed using the read-only
window.navigator property.
Syntax: window.navigator.property;
OR
navigator.property;

Methods used to display browser name and version:


1) appCodeName - Returns browser code name
2) appName - Returns browser name
3) appVersion - Returns browser version

2. List and state various properties of a window object. Write a JavaScript


that opens a popup window with the message “WELCOME To
SCRIPTING” on page load and “FUN WITH SCRIPTING” on page
unload. (Q4(b))

3. Write a JavaScript to set a crawling status bar message: “Welcome to the


Mystic World of JavaScript,” which starts crawling when the webpage
loads. (Q6(b))
<html>
<head>
<script>
var msg="Welcome to the Mystic World of JavaScript... "
var interval
function scroll()
{
msg=msg.substring(1)+msg.charAt(0)
window.status=msg
}
window.onload=function()
{
interval=setInterval(scroll,150)

CREATED BY PRACHI
}
</script>
</head>
</html>

2. Unit V: Regular Expression, Rollover, and Frames

 Regular Expressions 
1. Write a JavaScript that accepts a string and searches for the pattern
“MSBTE” using regular expressions. If the pattern is found, display
“Pattern is found,” otherwise display “Pattern is not found.” (Q4(a))
<html>
<body>
<script>
function find(input)
{
pattern=/MSBTE/
if(pattern.test(input))
{
document.write("Pattern is found")
}
else
{
document.write("Pattern is not found")
}
}
find("This is MSBTE example text")
</script>
</body>
</html>

2. Form regular expressions for:

 (i) Validation of an email address.


^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$

 (ii) Validation of an Aadhaar card in the format dddd – dddd –dddd.


^\d{4} - \d{4} - \d{4}$

 (iii) Validation of a phone number in the format (ddd) (dddddddd).


(Q5(b))

CREATED BY PRACHI
^\(\d{3}\) - \(\d{8}\)$

3. List any three properties of regular expression objects and state their use.
(Q6(c)(ii))

 Frames
1. Design a frameset layout for a webpage with the following frame
structure:

 Frame 1 (top frame), Frame 2 (left frame), Frame 3 (right frame),


Frame 4 (bottom frame). (Q6(c)(i))
 Rollover

CREATED BY PRACHI
1. Write an HTML script that displays laptop brand names (Lenovo, HP,
DELL) with a default image. When the mouse moves over a brand
name, the respective laptop image should display in an adjacent box.
(Q4(c))

<html>
<head>
<script>
function changeImage(brand) {
var img = document.getElementById("laptopImage");
if (brand === "lenovo")
{
img.src = "lenovo.jpg"
}
else if (brand === "hp")
{
img.src = "hp.jpg"
}
else if (brand === "dell")
{
img.src = "dell.jpg"
}
}
</script>
</head>
<body>
<div style="display: flex; align-items: center;">
<ul style="list-style-type: disc; padding-right: 20px; margin: 0;">
<li onmouseover="changeImage('lenovo')">Lenovo</li>
<li onmouseover="changeImage('hp')">HP</li>
<li onmouseover="changeImage('dell')">DELL</li>
</ul>
<div>
<img id="laptopImage" src="" alt="Laptop Image" width="300"
height="200">
</div>
</div>

CREATED BY PRACHI
</body>
</html>

3. Unit VI: Menus, Navigation, and Webpage Protection

 Status Bar
1. Write a JavaScript code to set a crawling message on the status bar:
“Welcome to the Mystic World of JavaScript,” starting when the page
loads. (Q6(b))
<html>
<head>
<script>
var msg="Welcome to the Mystic World of JavaScript... "
var interval
function scroll()
{
msg=msg.substring(1)+msg.charAt(0)
window.status=msg
}
window.onload=function()
{
interval=setInterval(scroll,150)
}
</script>
</head>
</html>

 Banner
1. Explain how to create and display a rotating banner in
JavaScript. (Q4(c))

Steps:
1. Create several banner advertisements using a graphics tool such as
Photoshop. You'll want to make more than one advertisement so you
can rotate them on your web page using a JavaScript.
2. Create an <img> element in your web page with the height and width
necessary to display the banner advertisement.
3. Build a JavaScript that loads and displays the banner advertisements
in conjunction with the <img> element.

<html>

CREATED BY PRACHI
<head>
<script>
MyBanners=newArray('CSS.jpg','CSS1.jpg','OSY.jpg','STE.jpg')
banner=0
function ShowBanners()
{
if (document.images)
{
banner++
if (banner==MyBanners.length)
{
banner=0}
document.ChangeBanner.src=MyBanners[banner]
setTimeout("ShowBanners()",5000)
}
}
</script>
<body onload="ShowBanners()">
<center>
<img src="banner1.jpg" width="400" height="800"
name="ChangeBanner"/>
</center>
</body>
</html>

 Menus
1. Write a JavaScript that demonstrates the use of a floating menu along
with respective HTML code. (Q5(a))
<html>
<body>
<div style="position:fixed">
<select name="Fruits">
<option value="">Fruits Name</option>
<option value="0">Apple</option>
<option value="1">Banana</option>
<option value="2">Orange</option>
<option value="3">Mango</option>
</select>
</div>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>

CREATED BY PRACHI
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br>
scroll down below
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br>
Again Scroll it
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br>
</body>
</html>

 Webpage Protection
1.State the use of hiding JavaScript and describe the steps needed to
accomplish it. (Q4(e))
One method to prevent users from accessing the context menu,
includes options such as viewing source, which inspecting
elements and saving images, is by disabling right-clicking through
event listeners or CSS properties.

Steps to hide 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 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 file, but you won't see the source code for the JavaScript.
• 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 file name that contains the JavaScript to the
src attribute of the <script> tag.

Webpage1.html:
<html>
<head>
<script src="code.js" language="Javascript"
type="text/javascript">

CREATED BY PRACHI
</script>
<body>
<h3> Right click on screen, Context Menu is disabled</h3>
</body>
</html>

Code.js:
window.onload=function()
{
document.addEventListener("contextmenu",function(e){
e.preventDefault();}, false);
}

CREATED BY PRACHI
CREATED BY PRACHI

You might also like