Saturday, January 5, 2013

html note

The following tags can be added to the head section: <title>, <style>, <meta>, <link>, <script>, <noscript>, and <base>.
The <base> tag specifies a default address or a default target for all links on a page:

<head>
<base href="http://www.w3schools.com/images/"><base target="_blank">
</head>

Metadata is data (information) about data.

The <meta> tag provides metadata about the HTML document. Metadata will not be displayed on the page, but will be machine parsable.

Meta elements are typically used to specify page description, keywords, author of the document, last modified, and other metadata.

The metadata can be used by browsers (how to display content or reload page), search engines (keywords), or other web services.

<meta> tags always goes inside the <head> element.
Define keywords for search engines:

<meta name="keywords" content="HTML, CSS, XML, XHTML, JavaScript">
Refresh document every 30 seconds:

<meta http-equiv="refresh" content="30">
<body>

<script>
document.write("Hello World!")
</script>

</body>
<a href="http://www.w3schools.com" style="text-decoration:none;">Visit W3Schools.com!</a>
p
{
color: red;
background-color:#EFE7D6;
border: '1pt solid black'
}

div
{
color: #FFFFFF;
background-color:#000000;
}
The required alt attribute specifies an alternate text for an image, if the image cannot be displayed.

The value of the alt attribute is an author-defined text:

<img src="boat.gif" alt="Big Boat">
<!DOCTYPE html>
<html>
<body>

<p>Click on the sun or on one of the planets to watch it closer:</p>

<img src="planets.gif" width="145" height="126" alt="Planets" usemap="#planetmap">

<map name="planetmap">
 <area shape="rect" coords="0,0,82,126" alt="Sun" href="sun.htm">
 <area shape="circle" coords="90,58,3" alt="Mercury" href="mercur.htm">
 <area shape="circle" coords="124,58,8" alt="Venus" href="venus.htm">
</map>

</body>
</html>

The HTML <div> Element

The HTML <div> element is a block level element that can be used as a container for grouping other HTML elements.

The <div> element has no special meaning. Except that, because it is a block level element, the browser will display a line break before and after it.

When used together with CSS, the <div> element can be used to set style attributes to large blocks of content.

Another common use of the <div> element, is for document layout. It replaces the "old way" of defining layout using tables. Using tables is not the correct use of the <table> element. The purpose of the <table> element is to display tabular data.

The HTML <span> Element

The HTML <span> element is an inline element that can be used as a container for text.

The <span> element has no special meaning.

When used together with CSS, the <span> element can be used to set style attributes to parts of the text.
<div> Defines a section in a document (block-level)
<span> Defines a section in a document (inline)
HTML forms are used to pass data to a server.
<form>
<fieldset>
 <legend>Personalia:</legend>
 Name: <input type="text"><br>
 Email: <input type="text"><br>
 Date of birth: <input type="text">
</fieldset>
</form>
<textarea rows="10" cols="30">
The cat was playing in the garden.
</textarea>
The <noscript> tag is used to provide an alternate content for users that have disabled scripts in their browser or have a browser that doesn’t support client-side scripting.

The <noscript> element can contain all the elements that you can find inside the <body> element of a normal HTML page.
To display a less than sign we must write: &lt; or &#60
Browsers will always truncate spaces in HTML pages. If you write 10 spaces in your text, the browser will remove 9 of them, before displaying the page. To add spaces to your text, you can use the &nbsp; character entity.
External scripts cannot contain <script> tags.
JavaScript is case sensitive.
When you assign a numeric value to a variable, do not put quotes around the value. If you put quotes around a numeric value, it will be treated as text.
JavaScript is weakly typed. This means that the same variable can be used as different types:

Example

var x                // Now x is undefined
var x = 5;           // Now x is a Number
var x = "John";      // Now x is a String
The following code creates an Array called cars:

var cars=new Array();
cars[0]="Saab";
cars[1]="Volvo";
cars[2]="BMW";
or (condensed array):

var cars=new Array("Saab","Volvo","BMW");
or (literal array):

Example

var cars=["Saab","Volvo","BMW"];
An object is delimited by curly braces. Inside the braces the object's properties are defined as name and value pairs (name : value). The properties are separated by commas:

var person={firstname:"John", lastname:"Doe", id:5566};
You can address the object properties in two ways:

Example

name=person.lastname;
name=person["lastname"]
This example creates an object called "person", and adds four properties to it:

Example

person=new Object();
person.firstname="John";
person.lastname="Doe";
person.age=50;
person.eyecolor="blue";

A variable declared (using var) within a JavaScript function becomes LOCAL and can only be accessed from within that function. (the variable has local scope).
Variables declared outside a function, become GLOBAL, and all scripts and functions on the web page can access it.
The lifetime JavaScript variables starts when they are declared.

Local variables are deleted when the function is completed.

Global variables are deleted when you close the page.
If you assign a value to variable that has not yet been declared, the variable will automatically be declared as a  GLOBAL variable.

This statement:

carname="Volvo";
will declare the variable carname as a global variable , even if it is executed inside a function.
!= is not equal
The JavaScript statements try and catch come in pairs.
JavaScript has several built-in objects, like String, Date, Array, and more.

In JavaScript you don’t define classes and create objects from these classes (as in most other object oriented languages).
Browser Name: " + navigator.appName

Alert "hello" every 3 seconds:

setInterval(function(){alert("Hello")},3000);
window.clearInterval(intervalVariable)
window.setTimeout("javascript function",milliseconds);
The window.setTimeout() method can be written without the window prefix.

The setTimeout() method will wait the specified number of milliseconds, and then execute the specified function.
A cookie is a variable that is stored on the visitor's computer. Each time the same computer requests a page with a browser, it will send the cookie too. With JavaScript, you can both create and retrieve cookie values.

The jQuery syntax is tailor made for selecting HTML elements and perform some action on the element(s).

Basic syntax is: $(selector).action()

A $ sign to define/access jQuery
A (selector) to "query (or find)" HTML elements
A jQuery action() to be performed on the element(s)
Examples:

$(this).hide() - hides the current element.

$("p").hide() - hides all <p> elements.

$(".test").hide() - hides all elements with class="test".

$("#test").hide() - hides the element with id="test".


HTML truncates multiple white-space characters to one single white-space:
With XML, the white-space in a document is not truncated.
In Windows applications, a new line is normally stored as a pair of characters: carriage return (CR) and line feed (LF). In Unix applications, a new line is normally stored as an LF character. Macintosh applications also use an LF to store a new line.

XML stores a new line as LF.

XML elements must follow these naming rules:

Names can contain letters, numbers, and other characters
Names cannot start with a number or punctuation character
Names cannot start with the letters xml (or XML, or Xml, etc)
Names cannot contain spaces
Any name can be used, no words are reserved.

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE note SYSTEM "Note.dtd">

<!DOCTYPE note
[
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>

W3C supports an XML-based alternative to DTD, called XML Schema:
It is possible to use CSS to format an XML document.
<?xml-stylesheet type="text/css" href="cd_catalog.css"?>
Formatting XML with CSS is not the most common method.
W3C recommends using XSLT instead.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

The XMLHttpRequest object is used to exchange data with a server behind the scenes.

The XMLHttpRequest object is a developer's dream, because you can:

Update a web page without reloading the page
Request data from a server after the page has loaded
Receive data from a server after the page has loaded
Send data to a server in the background

All modern browsers (IE7+, Firefox, Chrome, Safari, and Opera) have a built-in XMLHttpRequest object.

Syntax for creating an XMLHttpRequest object:

xmlhttp=new XMLHttpRequest();
Old versions of Internet Explorer (IE5 and IE6) use an ActiveX Object:

xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

Solving the Name Conflict Using a Prefix

Name conflicts in XML can easily be avoided using a name prefix.

This XML carries information about an HTML table, and a piece of furniture:
<root xmlns:h="http://www.w3.org/TR/html4/"
xmlns:f="http://www.w3schools.com/furniture">
<h:table>
 <h:tr>
   <h:td>Apples</h:td>
   <h:td>Bananas</h:td>
 </h:tr>
</h:table>

<f:table>
 <f:name>African Coffee Table</f:name>
 <f:width>80</f:width>
 <f:length>120</f:length>
</f:table>
In the example above, there will be no conflict because the two <table> elements have different names.
When using prefixes in XML, a so-called namespace for the prefix must be defined.

The namespace is defined by the xmlns attribute in the start tag of an element.

The namespace declaration has the following syntax. xmlns:prefix="URI".
Note: The namespace URI is not used by the parser to look up information.

The purpose is to give the namespace a unique name. However, often companies use the namespace as a pointer to a web page containing namespace information.
Everything inside a CDATA section is ignored by the parser.

A CDATA section starts with "<![CDATA[" and ends with "]]>":

JSON: JavaScript Object Notation.

JSON is syntax for storing and exchanging text information. Much like XML.

JSON is smaller than XML, and faster and easier to parse.
JSON uses JavaScript syntax for describing data objects, but JSON is still language and platform independent. JSON parsers and JSON libraries exists for many different programming languages.
For AJAX applications, JSON is faster and easier than XML:

Using XML

Fetch an XML document
Use the XML DOM to loop through the document
Extract values and store in variables
Using JSON

Fetch a JSON string
eval() the JSON string

JSON Syntax Rules

JSON syntax is a subset of the JavaScript object notation syntax.

Data is in name/value pairs
Data is separated by comma
Curly brackets holds objects
Square brackets holds arrays
{
"employees": [
{ "firstName":"John" , "lastName":"Doe" },
{ "firstName":"Anna" , "lastName":"Smith" },
{ "firstName":"Peter" , "lastName":"Jones" }
]
}
In the example above, the object "employees" is an array containing three objects. Each object is a record of a person (with a first name and a last name).
The first entry in the JavaScript object array can be accessed like this:

employees[0].lastName;
The file type for JSON files is ".json"
The MIME type for JSON text is "application/json"

AJAX = Asynchronous JavaScript and XML.

AJAX is not a new programming language, but a new way to use existing standards.

AJAX is the art of exchanging data with a server, and updating parts of a web page - without reloading the whole page.

The XMLHttpRequest object is used to exchange data with a server.

Send a Request To a Server

To send a request to a server, we use the open() and send() methods of the XMLHttpRequest object:

xmlhttp.open("GET","ajax_info.txt",true);
xmlhttp.send();

Method Description
open(method,url,async) Specifies the type of request, the URL, and if the request should be handled asynchronously or not.

method: the type of request: GET or POST
url: the location of the file on the server
async: true (asynchronous) or false (synchronous)
send(string) Sends the request off to the server.

string: Only used for POST requests
GET or POST?

GET is simpler and faster than POST, and can be used in most cases.

However, always use POST requests when:

A cached file is not an option (update a file or database on the server)
Sending a large amount of data to the server (POST has no size limitations)
Sending user input (which can contain unknown characters), POST is more robust and secure than GET


Web services can be discovered using UDDI
The basic Web services platform is XML + HTTP.
Web services platform elements:

SOAP (Simple Object Access Protocol)
UDDI (Universal Description, Discovery and Integration)
WSDL (Web Services Description Language)
SOAP is an XML-based protocol to let applications exchange information over HTTP.

Or more simple: SOAP is a protocol for accessing a Web Service.

SOAP stands for Simple Object Access Protocol
SOAP is a communication protocol
SOAP is a format for sending messages
SOAP is designed to communicate via Internet
WSDL is an XML-based language for locating and describing Web services.

WSDL stands for Web Services Description Language
UDDI is a directory service where companies can register and search for Web services.

UDDI stands for Universal Description, Discovery and Integration
UDDI is a directory for storing information about web services
UDDI is a directory of web service interfaces described by WSDL
UDDI communicates via SOAP

A SOAP message is an ordinary XML document containing the following elements:

An Envelope element that identifies the XML document as a SOAP message
A Header element that contains header information
A Body element that contains call and response information
A Fault element containing errors and status information

HTTP communicates over TCP/IP. An HTTP client connects to an HTTP server using TCP. After establishing a connection, the client can send an HTTP request message to the server:

POST /item HTTP/1.1
Host: 189.123.255.239
Content-Type: text/plain
Content-Length: 200
A SOAP method is an HTTP request/response that complies with the SOAP encoding rules.

HTTP + XML = SOAP

A SOAP request could be an HTTP POST or an HTTP GET request.

The HTTP POST request specifies at least two HTTP headers: Content-Type and Content-Length.

all p elements with class="center" will be center-aligned:

Example

p.center {text-align:center;}

<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>

No comments:

Post a Comment