CSS QB Ans
CSS QB Ans
A cookie is a small piece of data stored by the web browser on the user's computer. It is used
to remember information about the user between visits or during a single session on a
website. Cookies are commonly used for purposes like session management, personalization,
and tracking user behavior.
3. Explain how to create a web page and how to open a web page in new window
4. Write a JavaScript code to implement scroll by
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Scroll By Example</title>
</head>
<body>
<button onclick="scrollPage()">Scroll Down</button>
<script>
function scrollPage() {
// Scrolls the page down by 100px vertically
window.scrollBy(0, 100);
}
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Replace Text Example</title>
</head>
<body>
<p id="text">I like apple pie, apple juice, and apple tart.</p>
<button onclick="replaceText()">Replace "apple" with "orange"</button>
<script type="text/javascript">
function replaceText() {
var text = document.getElementById('text').innerHTML;
document.getElementById('text').innerHTML = replacedText;
}
</script>
</body>
</html>
8. Define banner and status bar
Banner: A banner is a prominent section, usually at the top of a webpage, used to display key
messages, advertisements, or announcements. It grabs users' attention and often contains
information like promotions, updates, or site navigation links.
Status Bar: A status bar is a small, usually horizontal bar at the bottom of the screen or
window. It provides real-time information about the application's state, such as page loading
progress, system notifications, or connection status.
In JavaScript, you can hide code by using **comments**. Comments are not executed by the
browser, allowing developers to add explanations or temporarily disable sections of code without
removing them.
1. Single-line comments: These are used to comment out a single line of code. They start with `//`,
and everything following it on that line is ignored by the browser.
2. Multi-line comments: These allow you to comment out multiple lines of code. They are enclosed
between `/*` and `*/`, and anything between these symbols is ignored.
By using comments, developers can hide code for debugging, documentation, or temporarily
disabling parts of the code without affecting the program's execution.
A menu that appears over the page when A menu that appears when the user right-clicks
triggered by an event, like clicking a button or a on an element, offering context-specific
link. options.
Used for general actions like navigation, tool Provides options specific to the element or
selection, or app-specific functions. context clicked (e.g., copying text, opening
links).
Visible when triggered by a specific event, such Appears when the user right-clicks an element
as clicking a button or menu item. and is usually related to the content clicked.
A button that opens a menu with different Right-clicking on a text field to see options like
navigation options. "Copy," "Paste," and "Select All."
11. Write a JavaScript to implement pull down menu and folding tree menu
Pulldown menu:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Folding Tree Menu</title>
<style>
ul {
list-style-type: none;
padding-left: 20px;
}
li {
cursor: pointer;
}
.nested {
display: none;
}
<ul>
<li onclick="toggleMenu(event)">Item 1
<ul class="nested">
<li>Sub-item 1</li>
<li>Sub-item 2</li>
</ul>
</li>
</ul>
<script>
function toggleMenu(event) {
var li = event.target;
li.classList.toggle("active");
}
</script>
</body>
</html>
12. Write a JavaScript to create a new window and giving a focus to new window
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>New Window Example</title>
</head>
<body>
<script>
function openNewWindow() {
var newWindow = window.open("", "", "width=400,height=300");
newWindow.focus();
}
</script>
</body>
</html>
1. Avoid `eval()`: `eval()` executes strings as code, which can be exploited by attackers. Use safer
alternatives to execute dynamic code.
2. Sanitize Input: Always clean user input to remove any potentially harmful characters. This
prevents attackers from injecting malicious code.
3. Use HTTPS: HTTPS encrypts communication between the server and browser, protecting sensitive
information. Always ensure your site uses `https://`.
4. Limit Sensitive Data: Keep sensitive data on the server, not in local storage or cookies. If you use
cookies, make them `HttpOnly` for added security.
5. Avoid Inline JavaScript: Inline JavaScript is vulnerable to attacks and harder to maintain. Use
external scripts and event listeners for cleaner, safer code.
Browser Location:
The browser location refers to the URL of the current webpage that is displayed in the browser's
address bar. It can be accessed and manipulated using JavaScript through the `window.location`
object. This allows you to retrieve or modify the URL, reload the page, or redirect the user to a
different page.
Browser History:
The browser history refers to the list of previously visited pages within the current browser session.
It can be accessed through the `window.history` object, which provides methods for navigating
through the history, such as going back to the previous page or moving forward to the next one. It
enables custom navigation behavior, such as implementing back and forward buttons within a web
application.
17. Explain frame and detail and write a script to create a frame
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Frames Example</title>
</head>
<body>
<frameset rows="50%,50%">
<frame src="https://www.example.com" name="frame1">
<frame src="https://www.wikipedia.org" name="frame2">
</frameset>
</body>
</html>
1. Use HTTPS:
- Encrypts data between the user's browser and the server, making it harder for attackers to
intercept information.
- Ensures that only safe and expected data is entered, preventing harmful scripts or malicious data
from affecting the website.
3. Session Management:
- Secures user sessions by using secure cookies and ensuring sessions expire after a set time to
prevent unauthorized access.
4. Password Security:
- Stores passwords in a secure way using encryption, preventing them from being compromised
even if the data is stolen.
1. Spring Security:
- Provides built-in features for authentication, authorization, and protection against common
attacks like CSRF and session hijacking.
- Ensures secure coding practices, like safe libraries and encrypted sensitive data, to avoid
vulnerabilities.
3. Database Security:
- Protects against SQL injection by using parameterized queries and ensures database credentials
are stored securely.
- Regularly checks logs for unusual activities and monitors the application for potential security
threats to respond quickly.
20. Write a script to implement banner, slideshow, pulldown menu, dynamically changing menu,
validating menu selection, floating menu, tab menu, popup menu
1. Banner:
2. Slideshow:
<div id="slideshow">
<img id="slide" src="https://via.placeholder.com/600x300?text=Slide+1" style="width:100%;">
</div>
<script>
let slides = [
"https://via.placeholder.com/600x300?text=Slide+1",
"https://via.placeholder.com/600x300?text=Slide+2",
"https://via.placeholder.com/600x300?text=Slide+3"
];
let currentSlide = 0;
function showSlide() {
document.getElementById('slide').src = slides[currentSlide];
currentSlide = (currentSlide + 1) % slides.length;
}
3. Pulldown menu
<select>
<option>Select an option</option>
<option>Option 1</option>
<option>Option 2</option>
<option>Option 3</option>
</select>