named anchors enabling users to jump to specific points within web documents

45
NAMEd anchors Enabling users to jump to specific points within Web documents

Post on 19-Dec-2015

221 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: NAMEd anchors Enabling users to jump to specific points within Web documents

NAMEd anchors

Enabling users to jump to specific points within Web documents

Page 2: NAMEd anchors Enabling users to jump to specific points within Web documents

Anchors and HREFs• We have seen that, to jump from one web

document to another, we specify the URL of the target document in the href attribute of the <a> tag which is linking to the target document

<a href=“some-url”>

• However, we can also use a name as the value of a href attribute

<a href=“#some-name”>

• This is used to jump to a point in a document

Page 3: NAMEd anchors Enabling users to jump to specific points within Web documents
Page 4: NAMEd anchors Enabling users to jump to specific points within Web documents

<h1> Dictionary of Computin Acronyms </h1>

<a name="contents"> <h2> List of Definitions </h2> </A>

<ul>

<li> <a href="#defn1"> Definition of a CPU </a></li>

<li> <a href="#defn2"> Definition of RAM </a></li>

<li> <a href="#defn3"> Definition of ROM </a></li>

</ul>

<a name="defn1"> <h2> CPU </h2> </a>

<p>

A CPU is a central processing unit. Blah blah blah blah blah blah

blah blah blah blah blah blah blah

blah blah blah blah blah blah blah

blah blah blah blah blah blah blah

blah blah blah blah blah blah blah

blah blah blah blah blah blah blah

</p>

<p> Go back to <a href=”#contents">List of Definitions</a>. </p>

Page 5: NAMEd anchors Enabling users to jump to specific points within Web documents

• We use <a> tags in two places:– to specify the hot-links– to specify the targets of the hot-links

• An <a> tag used to specify a hot-link target uses a name attribute instead of a href<a name=“some-Name”>

Example:

<a name=“content”> List of Defns </a>

… ….

<a href=“#content”> Go to list of defns </a>

Page 6: NAMEd anchors Enabling users to jump to specific points within Web documents

• An <a> element can also point to a specific point in a different document

• Example– In document 1:

<a name=“http://www.abc.com/doc2.html#place29”>A place in the middle of Document 2</a>

– In document 2<a name=“place29”>A place in the middle of this

document</a>

Page 7: NAMEd anchors Enabling users to jump to specific points within Web documents

Image maps

Another way to form hot-links

Page 8: NAMEd anchors Enabling users to jump to specific points within Web documents

• On the next slide, the image showing the Middle East can be used to link to other web documents

Page 9: NAMEd anchors Enabling users to jump to specific points within Web documents
Page 10: NAMEd anchors Enabling users to jump to specific points within Web documents

Clicking the dotted area below hot-links to a docm’nt on Turkey

Page 11: NAMEd anchors Enabling users to jump to specific points within Web documents

Clicking the dotted area below hot-links to a docm’t on the Med

Page 12: NAMEd anchors Enabling users to jump to specific points within Web documents

Clicking the dotted area below hot-links to a docm’nt on Egypt

Page 13: NAMEd anchors Enabling users to jump to specific points within Web documents

<style>

#image1 {width:140; neight:200}

</style>

<img src=“mideast.gif" id=“image1” usemap="#mymap">

….

….

….

….

<map name=“mymap”>

<area coords="0,50,100,80“ href="mediterranean.htm" >

<area coords="0,100,75,200“ href="egypt.htm“>

<area coords="50,0,140,30“ href="turkey.htm">

</map>

Page 14: NAMEd anchors Enabling users to jump to specific points within Web documents

• To use an img to provide hot-links, we need two things:– the img, which must have an explicitly stated

width and height– a map of this img, which specifies what areas

within the image are hot-links

• The map must have a name attribute

• The img must refer to the map which has this name

Page 15: NAMEd anchors Enabling users to jump to specific points within Web documents

<style>

#image1 {width:140; neight:200}

</style>

<img src=“mideast.gif" id=“image1” usemap="#mymap">

….

….

<map name=“mymap”>

</map>

Page 16: NAMEd anchors Enabling users to jump to specific points within Web documents

• The map is delimited by <map> and </map> tags

• Between these tags, we must have a series of <area> tags

• Each <area> tag must have two attributes– a coords attribute which specifies the upper-left

and lower-right corners of the area– a href attribute which specifies the document to

which the area forms a hot-link

Page 17: NAMEd anchors Enabling users to jump to specific points within Web documents

<img src=“mideast.gif" id=“image1” usemap="#mymap">

….

….

….

….

<map name=“mymap”>

<area coords="0,50,100,80“ href="mediterranean.htm" >

<area coords="0,100,75,200“ href="egypt.htm“>

<area coords="50,0,140,30“ href="turkey.htm">

</map>

Page 18: NAMEd anchors Enabling users to jump to specific points within Web documents

Map areas do not have to be rectangular

<map name=“mymap2”>

<area shape=“rect” coords="0,50,100,80“ href=“page1.htm" >

<area shape=“circle” coords="100,75,20“ href=“page2t.htm“>

<area shape=“poly” coords=“0,50,10,50,15,70,25,60,25,0“ href=“page2t.htm“>

</map>

Page 19: NAMEd anchors Enabling users to jump to specific points within Web documents

Cs 3314 got here on 8/11/2007

Page 20: NAMEd anchors Enabling users to jump to specific points within Web documents

Dynamic Web Pages

Page 21: NAMEd anchors Enabling users to jump to specific points within Web documents

Static Web Pages

• The web pages that we have created so far do not change after they are loaded by a browser -- they are static

• They provide only one feature that supports interactivity -- hotlinks

• Most hotlinks impose a lot of traffic on the Internet and impose a lot of computing load on servers

Page 22: NAMEd anchors Enabling users to jump to specific points within Web documents

Dynamic Web Pages

• Static web pages are good but good is never enough in the world of Information Technology

• As soon as static web pages were available, the desire arose for pages which were more interactive and which reduced the load on the Internet and on web servers

• People wanted more intelligence in web pages

Page 23: NAMEd anchors Enabling users to jump to specific points within Web documents

Adding intelligence to web pages

• To add intelligence to any computer entity, we must write a program which implements that intelligence

• There are two places where the programs can be executed:– on a server– on a broswer

Page 24: NAMEd anchors Enabling users to jump to specific points within Web documents

Server-side versus Client-side

• Choosing between server-side and client-side programming depends on several factors:– Privacy

• how private do you want your program to be

• will the program manipulate private data?

– Loading• are you concerned about overloading your server

• are you concerned about the Internet

Page 25: NAMEd anchors Enabling users to jump to specific points within Web documents

Server-side programming

• Advantages– Programs can be kept private: users only see

the output that your program send to them– Data can be kept private– Data can be kept permanently

• Disadvantages– adds to server workload– adds to network traffic– delays response to user

Page 26: NAMEd anchors Enabling users to jump to specific points within Web documents

Client-side programming

• Advantages– client computer does all the work– reduces traffic between server and client– enables faster response to user

• Disadvantages– users can see your program– users can see your data– programs cannot really keep permanent data

because users can throw them away

Page 27: NAMEd anchors Enabling users to jump to specific points within Web documents

Types of client-side programs

• Applets:– can avail of full power of general programming

languages (Java is the one usually used);– can be compiled and, therefore, semi-private

• Scripts– written in simpler languages (Javascript,

VBscript) developed specifically for the task– interpreted not compiled

Page 28: NAMEd anchors Enabling users to jump to specific points within Web documents

Client-side programming with Javascript

Page 29: NAMEd anchors Enabling users to jump to specific points within Web documents

Don’t be caught by the name

• Javascript is NOT Java

• History of Javascript:– Netscape were already developing a scripting

language (called LiveScript, I think) when Sun proposed Java as a platform-independent general programming language

– there was a bit of mutual band-wagon jumping• some syntax blending

• change of name from LiveScript(?) to Javascript

Page 30: NAMEd anchors Enabling users to jump to specific points within Web documents

What can Javascript programs do?

• Handle browser and/or user events

• create new browser frames and windows

• process forms

• process “cookies”

• interface with applet and server-side programs

• control multi-media objects on a web page

Page 31: NAMEd anchors Enabling users to jump to specific points within Web documents

User-event Handling

Page 32: NAMEd anchors Enabling users to jump to specific points within Web documents

Types of user events

• when the mouse button is clicked on an element;

• when the mouse button is double-clicked on an element;

• when the mouse button is pressed over an element;

• when the mouse button is released over an element;

• when the mouse is moved onto an element;

Page 33: NAMEd anchors Enabling users to jump to specific points within Web documents

Types of user events (contd.)

• when the mouse is moved while over an element;

• when the mouse is moved away from an element;

• when a key is pressed and released over an element;

• when a key is pressed down over an element;

• when a key is released over an element.

Page 34: NAMEd anchors Enabling users to jump to specific points within Web documents

Consider following web page

• It has two paragraphs of text

• While user moves mouse onto first paragraph, its font size will increase

• While user moves mouse away from second paragraph, its color will change to red

Page 35: NAMEd anchors Enabling users to jump to specific points within Web documents
Page 36: NAMEd anchors Enabling users to jump to specific points within Web documents
Page 37: NAMEd anchors Enabling users to jump to specific points within Web documents
Page 38: NAMEd anchors Enabling users to jump to specific points within Web documents

How did he do that?

• By associating two very short Javascript programs with each paragraph, each program with a different event:– First paragraph:

• one program executes when mouse enters box

• other program executes when mouse leaves box

– Second paragraph:• one program executes when mouse enters box

• other program executes when mouse leaves box

Page 39: NAMEd anchors Enabling users to jump to specific points within Web documents

Associating programs with events

• Events happen to content elements

• So, contents elements can have attributes whose – names indicate the events we want to handle

and – whose values are the Javascript programs we

want to execute when these events occur

Page 40: NAMEd anchors Enabling users to jump to specific points within Web documents

Names for events

• onclick, when the mouse button is clicked on an element;

• ondblclick, when the mouse button is double-clicked on an element;

• onmousedown, when the mouse button is pressed over an element;

• onmouseup, when the mouse button is released over an element;

• onmouseover, when the mouse is moved onto an element;

• onmousemove, when the mouse is moved while over an element;

• onmouseout, when the mouse is moved away from an element;

• onkeypress, when a key is pressed and released over an element;

• onkeydown, when a key is pressed down over an element;

• onkeyup, when a key is released over an element.

Page 41: NAMEd anchors Enabling users to jump to specific points within Web documents

Extract from HTML specification

<p onmouseover='this.style.fontSize=32'

onmouseout='this.style.fontSize=14'>

Whenever you place your mouse over me, my Font Size will increase to help you read me.

</p>

Page 42: NAMEd anchors Enabling users to jump to specific points within Web documents

Analysis of extract:

<p onmouseover='this.style.fontSize=32'

onmouseout='this.style.fontSize=14'>

• Attributes are of form:

someEventName=‘someJavascript’

Page 43: NAMEd anchors Enabling users to jump to specific points within Web documents

Analysis continuedonmouseover='this.style.fontSize=32'

• Javascript is enclosed by apostrophes

• Case is ESSENTIAL in Javascript

• this (note all lower-case) refers to the element to which the Javascript is attached

• this.style refers to the style for this element

• this.style.fontSize refers to the font-size property of the style for this element

Page 44: NAMEd anchors Enabling users to jump to specific points within Web documents

Another extract from HTML spec

<p onmouseover='this.style.color="red"'

onmouseout='this.style.color="black"'>

• this.style.color refers to the color property of the style for this paragraph

• the values specified for the color must be enclosed in quotes

Page 45: NAMEd anchors Enabling users to jump to specific points within Web documents

Full HTML specification<html>

<head>

<title> Simple Mouse Event </title>

</head>

<body>

<h1> Some Subject or Other </h1>

<p onmouseover='this.style.fontSize=32’ onmouseout='this.style.fontSize=14'>

Whenever you place your mouse over me, my Font Size will increase to help you read me.

</p>

<h1> Another Subject </h1>

<p onmouseover='this.style.color="red"’ onmouseout='this.style.color="black"'>

Whenever you place your mouse over me, my color will change to help you read me.

</p>

</body>

</html>