Showing posts with label HTML. Show all posts
Showing posts with label HTML. Show all posts

Embedding JavaScript in HTML

The <script> is to assist the browser in recognizing lines of code in an HTML document as belonging to a script, you surround lines of script code with a
<script>...</script> tag set. tag. Script with src,
<script src="my-script.js" type="text/javascript"></script>
The purpose is to define functions, objects, and variables. Functions will later be triggered by buttons, other user events, inline script tags with body content, etc. script with body content

<script type="text/javascript">JavaScript code</script>

Purpose is to define functions, objects, and variables. To directly invoke code that will run as page loads, to output HTML content built by JavaScript Don't use this approach for defining functions or for doing things that could be done in external files. Slower (no browser caching) and less reusable.

Learn By Example-1:
//Example (phish.js)
function getMessage() {
var amount = Math.round(Math.random() * 100000);
var message =
"You won $" + amount + "!\n" +
"To collect your winnings, send your credit card\n" +
"and bank details to oil-minister@phisher.com.";
return(message);
}
function showWinnings1() {
alert(getMessage());//"alert" pops up dialog box
}
function showWinnings2() {
document.write("<h1><blink>" + getMessage() +
"</blink></h1>");
//"document.write" inserts text into page at current location.

//Example (loading-scripts.html)
<!DOCTYPE ...><html xmlns="http://www.w3.org/1999/xhtml">
<head><title>Loading Scripts</title>
...
<script src="./scripts/phish.js"//Loads script from previous page
type="text/javascript"></script>
</head>
<body>
...
<input type="button" value="How Much Did You Win?"
onclick='showWinnings1()'/>
//Calls showWinnings1 when user presses
//button. Puts result in dialog box.
...
<script type="text/javascript">showWinnings2()</script>
//Calls showWinnings2 when page is loaded in
//browser. Puts result at this location in page.
...
</body></html>

Adding Color in HTML

A collection of nearly 150 color names are supported by all major browsers.When you create a web page you will want to use different background and text colour's and to add images. This makes the site more attractive to visitors and generally makes the website look better. Take care not to make the text and background colour the same... :-0
To add color you would add the following HTML code into the body of your text file.

<body bgcolor = "#0000FF">


Notice how instead of saying We have used some strange looking code. Dont worry this is called "Hexadecimal colour" and can be used for inserting complex colours into your website.Check out some more Hexadecimal values below,

Hex values are written as 3 double digit numbers, starting with a # sign.

Color Color HEX Color RGB

#000000 rgb(0,0,0)

#FF0000 rgb(255,0,0)

#00FF00 rgb(0,255,0)

#0000FF rgb(0,0,255)

#FFFF00 rgb(255,255,0)

#00FFFF rgb(0,255,255)

#FF00FF rgb(255,0,255)

#C0C0C0 rgb(192,192,192)

#FFFFFF rgb(255,255,255)

16 Million Different Colors

The combination of Red, Green and Blue values from 0 to 255 gives a total of more than 16 million different colors to play with (256 x 256 x 256). Most modern monitors are capable of displaying at least 16384 different colors. If you look at the color table below, you will see the result of varying the red light from 0 to 255, while keeping the green and blue light at zero.

Red Light HEX RGB

#000000 rgb(0,0,0)

#080000 rgb(8,0,0)

#100000 rgb(16,0,0)

#180000 rgb(24,0,0)

#200000 rgb(32,0,0)

#280000 rgb(40,0,0)

#300000 rgb(48,0,0)

#380000 rgb(56,0,0)

#400000 rgb(64,0,0)

#480000 rgb(72,0,0)

#500000 rgb(80,0,0)

#580000 rgb(88,0,0)

#600000 rgb(96,0,0)

#680000 rgb(104,0,0)

#700000 rgb(112,0,0)

#780000 rgb(120,0,0)

#800000 rgb(128,0,0)

#880000 rgb(136,0,0)

#900000 rgb(144,0,0)

#980000 rgb(152,0,0)

#A00000 rgb(160,0,0)

#A80000 rgb(168,0,0)

#B00000 rgb(176,0,0)

#B80000 rgb(184,0,0)

#C00000 rgb(192,0,0)

#C80000 rgb(200,0,0)

#D00000 rgb(208,0,0)

#D80000 rgb(216,0,0)

#E00000 rgb(224,0,0)

#E80000 rgb(232,0,0)

#F00000 rgb(240,0,0)

#F80000 rgb(248,0,0)

#FF0000 rgb(255,0,0)

Shades of Gray

Gray colors are displayed using an equal amount of power to all of the light sources. To make it easier for you to select the right gray color we have compiled a table of gray shades for you:


RGB(0,0,0) #000000

RGB(8,8,8) #080808

RGB(16,16,16) #101010

RGB(24,24,24) #181818

RGB(32,32,32) #202020

RGB(40,40,40) #282828

RGB(48,48,48) #303030

RGB(56,56,56) #383838

RGB(64,64,64) #404040

RGB(72,72,72) #484848

RGB(80,80,80) #505050

RGB(88,88,88) #585858

RGB(96,96,96) #606060

RGB(104,104,104) #686868

RGB(112,112,112) #707070

RGB(120,120,120) #787878

RGB(128,128,128) #808080

RGB(136,136,136) #888888

RGB(144,144,144) #909090

RGB(152,152,152) #989898

RGB(160,160,160) #A0A0A0

RGB(168,168,168) #A8A8A8

RGB(176,176,176) #B0B0B0

RGB(184,184,184) #B8B8B8

RGB(192,192,192) #C0C0C0

RGB(200,200,200) #C8C8C8

RGB(208,208,208) #D0D0D0

RGB(216,216,216) #D8D8D8

RGB(224,224,224) #E0E0E0

RGB(232,232,232) #E8E8E8

RGB(240,240,240) #F0F0F0

RGB(248,248,248) #F8F8F8

RGB(255,255,255) #FFFFFF

If you are finding all of these different colour codes confusing dont worry!
As well as using the Hexadecimal method, you can also use good old fasioned English! Meaning that placing the following code into your HTML file would have the exact same effect:

<body bgcolor = "blue">


When inserted into your code, the code should look like this:

<html>
<head>
<title>My Own Home Page </title>
</head>
<body>
<body bgcolor= "blue">
<H1> I am Your-Name and this is my web Page!</H1>
</body>

Test your file by saving it, remember to save it as "index.html" and make sure you slect "All Files" from the save as type box. Now that we have our background colour sorted out, we can now alter the text colour. We go about doing this in the same way. This is the code we need to insert into our webpage:

<font color="Red">Text that you want to make red goes here</font>

Notice that you must put </font> after the text has ended. If you didnt insert the </font> then your entire document would have the text as red. This isnt to important for now but if you ever have more than one text colour on a page this may become a problem. Here is how your code should now look:

<html>
<head>
<title>My Own Home Page </title>
</head>
<body>
<body bgcolor= "blue">
<font color="Red">
<H1> I am Your-Name and this is my web Page!</H1>
</font>
</body>

Note:
A common error when coding with colours and HTML in general are simple spelling mistakes.
Remember that when typing "color" it is the american spelling, make sure you dont use the english spelling "colour" or your HTML wont work.

Write a program in HTML to demonstrate the use of basic tags.

HTML stands for "Hyper Text Markup Language".HTML is the bricks and mortar of the WWW. Without HTML the World Wide Web could not have become as important as it is today. HTML is a document formatting language common the all computers on the WWW. Html permits cross platform communication between Macs, Apples, SUNs, PCs and others to view a document in a similar way. Every webpage that you visit uses HTML in some way, you can view the HTML code behind a website in Internet Explorer by selecting: View>Source.
HTML has two sections, the "Head" section and the "Body" section. The head section is where the information about the web page is put for the browser. This has nothing to do with the heading that you want to see on your web page. Things that can be stored in the head section include Keywords for search engines or the title of your webpage. The body section is where the web page is coded. This is where you put the information for your web page.We are now going to create our very own webpage, for now we are going to create a simple page telling people your name.Please follow these instructions:
  • Create a new folder so you have some where to save your website, call this folder anything you wish, this is where all pages and images for your website will be saved.
  • Open notepad and type the following code, you may change the code in yellow to suit your needs: Type the following code into NotePad.
    <html>
    <head>
    <title>My Own Home Page </title>
    </head>
    <body>
    <H1> I am Your-Name and this is my web Page!</H1>
    </body>
    </html>

  • Thats it! You have just coded your first webpage. Now save the notepad file by selecting "Save as" (make sure you save the file in the folder you have just created) In the filename box type "index.html" and from the "Save as type" box select "All Files"Then click "Save".
  • You are now ready to view your first webpage, navigate to the folder where you saved the file, double click on it and you will see your first webpage. It should look something like this:

 

About Me

It's Me!Hi, I'm Moinuddin. I'm a Software Engineer at WIPRO working on Microsoft .NET Technology. I'm interested in a wide range of technology topics, mainly Microsoft including Windows Azure, WCF, WPF, Silverlight and any other cool technology that catches the eye.

Site Info

ProjectCSharp.com is mainly about demonstrating real time examples in different technologies like ASP.NET, WCF, WPF, Silverlight, Azure etc..,

Followers

Help Links

Project CSharp (C#) Copyright © 2011. All Rights Reserved.