CSS Chapter 4
CSS Chapter 4
Unit - IV
• Apart from well-designed web pages with easily navigable layouts, learning about
users and using information gained about them is also very effective.
• Accessing the user’s local file system from a web application is pretty much off
limits because of security restrictions included in browsers.
• Cookie property of document object can be used to create and retrieve cookie
data from within a JavaScript code.
Prepared By: Khan Mohammed Zaid, Lecturer, Comp. Engg.,
3
MHSSP
Cookies
• Cookies are small text files that a browser stores in the visitor’s computer.
❑Personalization:
▪ Advertisements based on items or part of websites you visit.
❑Tracking:
▪ Suggesting items based on items previously used/viewed
• Default is FALSE.
• It is an optional attribute.
• It is an optional attribute.
• If set to "/", the cookie will be available within the entire domain.
If set to "/php/", the cookie will only be available within the php
directory and all sub-directories of php.
• The default value is the current directory that the cookie is being
set in.
• It is an optional attribute.
Prepared By: Khan Mohammed Zaid, Lecturer, Comp. Engg.,
11
MHSSP
Cookies
• Attributes of cookies: HTTPOnly
• If set to TRUE the cookie will be accessible only through the HTTP
protocol (the cookie will not be accessible by scripting languages).
• This setting can help to reduce identity theft through XSS (Cross-
site Scripting) attacks.
• Default is FALSE.
• Default is 0.
• It is an optional attribute.
• Cookie values may not include semicolons, commas, or whitespace. For this
reason, you may want to use the JavaScript escape() function to encode the
value before storing it in the cookie.
• where name is the name of the cookie and value is its string value.
• You can use strings' split() function to break a string into key and values
• If you have a page with no frames, there will be just one window object.
• However, if you have more than one frame, there will be one window object for
each frame.
where:
URL: specifies the URL of the page to open. If no URL is specified, a new
window/tab with about:blank is opened.
name: specifies the target attribute or the name of the window. Following
values are supported:
_blank: URL is loaded into a new window or tab.
_parent: URL is loaded into the parent window.
_self: URL replaces the current page.
_top: URL replaces any framesets that may be loaded.
name: The name of the window.
Prepared By: Khan Mohammed Zaid, Lecturer, Comp. Engg.,
20
MHSSP
Opening new Windows
specs: A comma separated lists of items. E.g. fullscreen, height,width, left,
top, menubar, scrollbars, titlebar, toolbar.
replace: Specifies whether the URL creates a new entry or replaces the
current entry in the history list. (true/false)
• When you click same button multiple times to open a window, it will replace the
previous child window with a new window with overwritten data.(only 1 window
is visible)
• To open multiple windows from single button (keeping each child window), use
different window name for each click.(provide a rand number for window name)
• This method makes a request to bring the current window to the foreground.
Syntax: window.focus()
• moveto(x,y): moves a window’s left and top edge to the specified coordinates.
• scrollby()
• scrollto()
• For this method to work, the visibility property of the window’s scrollbar must be
set to true.
Syntax: window.scrollby(xnum,ynum)
Where:
xnum: how many pixels to scroll by, along x-axis. +ve value will scroll
to the right, - ve value will scroll to the left.
ynum: how many pixels to scroll by, along y-axis. +ve value will
scrolldown, -ve value will scrollup.
Syntax: window.scrollto(xpos,ypos)
Where:
xpos: The coordinate to scroll to along x-axis.
ypos: The coordinate to scroll to along y-axis.
• One-shot timer triggers just once after a certain period of time and second type
of timer continually triggers at set of intervals.
• Common uses for timers include advertisement banner pictures that change at
regular intervals or display the changing time in a web page.
Syntax: window.setTimeout(function,milliseconds);
Where:
function: it is a function you want to execute.
millisecond: millisecond delay until the code is executed.
• Method returns the timer’s unique ID, an integer value. It can be used to stop
the timer firing .
Syntax: window.clearTimeout(timeoutVariable)
where:
timeoutVariable: it is the variable returned from setTimeout() method.
Syntax: window.setInterval(function,milliseconds);
Where:
function: it is a function you want to execute.
millisecond: millisecond delay until the code is executed.
• Method returns the timer’s unique ID, an integer value. It can be used to stop
the timer firing .
Prepared By: Khan Mohammed Zaid, Lecturer, Comp. Engg.,
42
MHSSP
Timers
<html>
<head>
</head>
<body onload="window_onload()">
<script>
var timerID;
function window_onload()
{
setInterval(func,3000); }
function func()
{
alert("hello"); }
</script></body>
</html> Prepared By: Khan Mohammed Zaid, Lecturer, Comp. Engg.,
43
MHSSP
Timers
• Regular Interval Timer:
Syntax: window.clearInterval(timerVariable)
where:
timerVariable: it is the variable returned from setTimeout() method.
• The history object is part of the window object and is accessed through the
window.history property.
• Property:
❑ Length: Returns the number of URLs in the history list.
✓It returns atleast 1, because the list includes the currently loaded page.
✓Maximum length is 50.
✓This property is read-only.
✓Syntax: history.length
Prepared By: Khan Mohammed Zaid, Lecturer, Comp. Engg.,
48
MHSSP
Browser History
• Methods:
❑ back(): Loads the previous URL in the history list.
✓It is same as clicking the back button in a browser.
✓Syntax: history.back();