Saturday, April 30, 2016

Welcome

Welcome

I have created this blog to pass on some stuff about web programming. 

I'll be covering everything from the absolute beginning and working up to server side programming.

As most people will be on Windows I'll be concentrating what you have to do to get up and running on that.

Let's go... 

Thursday, March 31, 2016

HTML intro

Part 1 - What is HTML

Introduction

The short answer is HyperText Markup Language. 

This is a practical guide not a history lesson so I'll keep the history short. If you want to read more of how HTML developed have a look here HTML history. Early on it was decided that the internet standards would be 'open' meaning that they would published so anyone can use them. In most cases this works really well and an HTML page looks the same in Google Chrome, Mozilla Firefox and Microsoft internet explorer 9 times out of 10.

Structure

The top level is the site. A site is a collection of pages in a domain.

I think sites and pages are familiar enough but it's worth looking at what a domain is more closely. The internet is big. And every page has to have a totally unique name. Let's have a look at the unique name of a page:

http://www.ajscrafts.co.uk/common/home.aspx

And let's pick it to peices:

http://www.ajscrafts.co.uk/common/home.aspx

This is the protocol. You'll be familiar with http and https (hypertext transfer protocol(secure)) because this protocol delivers almost all web pages. We'll mainly be using http. The s is important though. If the site you are on uses https, you can be pretty sure the server you are talking to is who it says it is and that anything you send and receive is encrypted.

http://www.ajscrafts.co.uk/common/home.aspx

This is the fully qualified domain name. If you want to use a domain name you have to register it. This allows the domain name authorities to ensure domains are unique. It tells the traffic routing software exactly which server the page is held on. The servers are actually numbered, this is called the IP address. The number that relates to ajscrafts.co.uk is 91.102.64.149 right now. The number could change because the hosting shares IP addresses. Every device on the internet has it's own IP address and we are running out. A new standard is being rolled out called IPv6 but this is well beyond the discussion here.

http://www.ajscrafts.co.uk/common/home.aspx

The last part tells the server where to find the page to deliver. For convenience files can be organised into directories. The home.aspx file is in the directory common.

Pages

The important thing to us is the page. A page is a single file on a disk somewhere that can be delivered by giving its url. So let's make a page...

Monday, February 29, 2016

My first page

Making a web page

For now just follow these steps, I'll explain what we are doing later...

1. Open Notepad

Notepad is a very simple text editor. It comes with windows. You might have a desktop icon for it or you may have to look for it in the windows accessories program group. When it is open it looks like this:


2. Type in your HTML

Type this in exactly as shown:

<html>
<head>
<title>My First Page</title>
</head>
<body>
This is my first bit of HTML. Pretty good eh!
</body>
</html>

3. Save it

From the notepad file menu select save as. You'll see a dialog like this:

You will probably want to make a directory somewhere to save this so you know where it is. 
I've called mine ...\htmlblog\code.html. You can call yours what you like but use the extension HTML if you want it to automatically open in a browser.

4. Close notepad

5. Open the file

Open File Explorer and navigate to where you saved the file.
Double click it.

6. Did you get it right?

Your page should open and you should see this in the browser:
The title on the page or the tab should look like this
If it doesn't then do the troubleshooting...

 7. Troubleshooting

Browser did not open: You probably don't have your browser associated with HTML file types. Go back to file explorer and right click the file and use Open With option.

Text or title did not appear: Open the file with Notepad (right click and Open With.) Check very carefully what you typed. Correct it, save it and try opening the file in the browser again.

Text looks right to me: Cut and paste it exactly as it is in notepad into a comment here and I'll have a look.

Something else happened: Put a comment on this post so I can add it to the article.

8 Make your HTML more readable

On a small page like this the HTML is easy to read but when things get a bit more complicated you will want to use indents to help you read understand the page. Whitespace is ignored when the page is rendered so you can put in some tabs or spaces. This is how I would do it:

<html>
  <head>
    <title>My First Page</title>
  </head>
  <body>
This is my first bit of HTML. Pretty good eh!
  </body>
</html>

You can save this and open it in the browser again...it should look exactly the same.

Code Walkthrough

The page file gives instruction to the browser what it should do with the file. This is the markup bit of the HTML. The markup we have used is in the form of tags, those bits in angle brackets < >. There are some rules with tags:
  • They must be terminated with a </ end tag (there is a way of making an empty tag... later...)
  • If the browser doesn't understand them it will ignore them
  • They are 'nested' so if you open a tag you have to terminate it before you terminate an outer tag
  • Some tags must have a specific parent tag
  • Tags are not case sensitive. 
The tags we have used are:

<html>: This always has to be the outer tag. You can't have a page without it.
<head>: You have to have a head tag inside the html tag. It will contain a lot of things that tell the browser how to handle the page but it never renders inside the display area of the browser.
<title>: Tells the browser to display the text inside the tag as a title. Usually in a tab or on the title bar of the browser. The title tag must be inside the head tags.
<body>: Anything you want to show in the main body of the browser has to between the body tags.

Exercise

Get used to editing and saving the file. Change the text in the title and body.
Purposely misspell some of the tags. Have a look at what happens in the browser.

Tuesday, February 2, 2016

First hypertext

Hypertext


Hypertext relates to the ability of web pages to link to other pages. Like this.

In this section we'll add a link to our page.

For historical reasons links are known as anchors and are placed in an <a> tag. The anchor tag that is behind the word this above looks like this:

<a href="http://www.google.com/" target="_blank">this</a>

The parts of the anchor tag are:

<a : the start of the tag



<a href="http://www.google.com/": a tag property. The href property value is the url of the page that will be loaded when the link is clicked. The rules for all properties are:

  • They should have a value (tags without values are abominations but they have been used in the past, mainly by Internet Explorer)
  • The value must be surrounded in quotes. Double or single quotes can be used.
  • If the property is not recognised or is not appropriate to the tag it will be ignored.
Because this link is going to another site the fully qualified url has to be given. If the link is to a page on the same site then a relative url, made up of the directory and page name, can be used because the browser can guess the protocol and domain.

<a href="http://www.google.com/" target="_blank">this</a>: Another property. The target property tells the browser how to open the link. The _blank value opens it in either a new page or new tab.


<a href="http://www.google.com/" target="_blank">this</a>: The text that will be displayed. The browser takes care of the colour and underlines on the link. The de facto standard seems to be blue with an underline but later we will see how to override this using style sheets.

<a href="http://www.google.com/" target="_blank">this</a>: The end tag.

Exercise


Put a link to this blog on your page. Hint: the url is in the browser url box...