css imp
css imp
str.substring(start,
str.substr(start, length)
Syntax end)
Accepts
Does not accept
negative start (counts
negative start or end
Negative Index from the end)
setTimeout(function, milliseconds);
example
// program to display a text using setTimeout method
function greet() {
console.log('Hello world');
}
setTimeout(greet, 3000);
console.log('This message is shown first');
5. The setTimeout() method calls the function only once after the
time interval (here 3 seconds).
6. However, in the above program, since the function is calling itself,
the program displays the time every 3 seconds.
7. This program runs indefinitely (until the memory runs out).
The splice() method can be used to add new items to an array, and removes elements
from an array. Syntax:
arr.splice(start_index,removed_elements,list_of_elemnts_to_be_added); Parameter:
•The first parameter defines the position where new elements should be added
(spliced in). •The second parameter defines how many elements should be removed.
•The list_of_elemnts_to_be_added parameter define the new elements to be
added(optional). Output:
The splice() method can be used to add new items to an array, and removes elements
from an array.
Syntax: arr.splice(start_index,removed_elements,list_of_elemnts_to_be_added);
Parameter:
•The first parameter defines the position where new elements should be added
(spliced in).
•The second parameter defines how many elements should be removed.
•The list_of_elemnts_to_be_added parameter define the new elements to be
added(optional).
EXAMPLE=
<html>
<body>
<script>
var fruits = ["Banana", "Watermelon", "Chikoo", "Mango", "Orange", "Apple"];
document.write(fruits+"<br>");
fruits.splice(2,2, "Lemon", "Kiwi");
document.write(fruits+"<br>");
fruits.splice(0,2); //removes first 2 elements from array
document.write(fruits+"<br>");
</script>
</body>
</html>
Q. list ways of protecting your web page and describle any one of them.
ANS =
1) Hiding Your Code by disabling Right Mouse Click:
2) Hiding JavaScript
3) Concealing Your E-mail Address
There is nothing secret about your web page. Anyone with a little computer
knowledge can use a few mouse clicks to display your HTML code, including your
JavaScript, on the screen. Following are the ways to protect web pages: 1) Hiding
Your Code by disabling Right Mouse Click: 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 tag of the web page. There
is nothing secret about your web page. Anyone with a little
computer knowledge can use a few
mouse clicks to display your HTML code, including your JavaScript, on the
screen.
Following are the ways to protect web pages:
1) Hiding Your Code by disabling Right Mouse Click:
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.
<html>
<head>
<script>
window.onload = function()
{
document.addEventListener("contextmenu", function(e)
{
e.preventDefault();
}, false);}
</script>
<body>
<h3>Right click on screen,Context Menu is disabled</h3>
</body>
</html>
The preventDefault() method cancels the event if it is cancelable, meaning
that the default action that
belongs to the event will not occur.
Q. Explain how to create and display Rotating Banner in JavaScript with example. ]
Ans: Following steps must be follow for creating banner in javascript:
1. Load banner advertisements into an array.
2. Determine whether the browser supports the image object.
3. Display a banner advertisement. 4. Pause before displaying the next banner
advertisement. EXAMPLE
Q. Explain text and image rollover with suitable example.
Ans: Text rollover: We can also create a rollover and rollback for text using the onmouseover
and onmouseout.
EXAMPLE:
<html>
<head>
Q. Write a javascript program to demonstrate java intrinsic function.
ANS= An intrinsic function is often used to replace the Submit button and the Reset button
with your own graphical images, which are displayed on a form in place of these buttons.
Q.Describe how to link banner advertisement to URL with example.
ANS= 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.
Q.State what is regular expression. Explain its meaning with the help of a suitable example.
ANS= A regular expression is an object that describes a pattern of characters. The JavaScript
RegExp class represents regular expressions, and both String and RegExp define methods
that use regular expressions to perform powerful pattern-matching and search-and-replace
functions on text. A Regular Expression is a sequence of characters that constructs a search
pattern. When you search for data in a text, you can use this search pattern to describe what
you are looking for.
Syntax: A regular expression is defined with the RegExp () constructor as: var pattern = new
RegExp(pattern, attributes);