Mahbubul Majumder, PhD
Oct 14, 2014
Shell scripting
Web scripting
Data Handling
Scripting makes the tedious job easier
Some reasons to learn scripting
It is important for creating online data products
QUIZ:
Is RStudio nothing but a HTML page with embedded JavaScript?
HTML: Hyper Text Markup Language
HTML tag syntax
<tag></tag>
Structural tags
<html></html>
<head></head>
<body></body>
Header tags
<h1></h1>
<h2></h2>
<h3></h3>
<h4></h4>
Paragraph tags
<p></p>
Table tags
<table></table>
<tr></tr>
for rows<td><td>
for columnsAnchor tag
<a></a>
for hyperlinkList tag
<ul></ul>
for unordered list<ol><ol>
for ordered list<li></li>
for list item Write codes in plain text editor and save file as .html extension (say test.html). Open test.html using any browser.
First declare document type
<!DOCTYPE html>
Write everything within HTML tags
<html>
..everything goes here ..
</html>
<head>
tag may contain tags like
<title>, <style>, <meta>, <link>, <script>
<body>
tag contains the actual content
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1> My Heading </h1>
<p> My first paragraph.</p>
<p> My second paragraph goes here. It is rather a long text. It could have multiple lines.</p>
</body>
</html>
My first paragraph.
My second paragraph goes here. It is rather a long text. It could have multiple lines.
List of common attributes of HTML tags
Attribute | Description |
---|---|
alt | Specifies an alternative text for an image |
disabled | Specifies that an input element should be disabled |
href | Specifies the URL (web address) for a link |
id | Specifies a unique id for an element |
src | Specifies the URL (web address) for an image |
style | Specifies an inline CSS style for an element |
title | Specifies extra information about an element (displayed as a tool tip) |
value | Specifies the value (text content) for an input element. |
Example
<a href = 'www.google.com'> This is google link </a>
<p id = 'para1'> My first paragraph </p>
<body style = 'color:blue'> text goes here </body>
<img src='myPic.jpg' width='104' height='142'>
CSS = Cascading Style Sheets
Three ways you can do it
<style>
element in the HTML <head>
sectionExternal CSS are linked in <head>
<head>
<link rel="stylesheet" href="path/styles.css">
</head>
<head>
tag.<head>
<style>
h1 {
color:blue;
font-family:verdana;
font-size:300%;
}
p {
color:red;
font-family:courier;
font-size:160%
}
</style>
</head>
We may want a style specific to a single element. This can be done through id attribute
In html we write
<p id='p1'>My paragraph</p>
p#p1{
color:red
}
We may want a style specific to a group of elements. This can be done through class attribute
In html we write
<p class='c1'>My paragraph</p>
p.c1{
color:red
}
Some of the most common CSS properties and examples of how to write
property | Description | Examples |
---|---|---|
color | property for text colors | color:blue |
background-color | background color | background-color:lightgrey |
font-family | property for text fonts | font-family:garamond |
font-size | property for text sizes | font-size:150% |
text-align | text alignment | text-align: center |
border | property for visible element borders | border:1px solid black |
padding | property for space inside the border | padding:10px |
margin | property for space outside the border | margin:30px |
Syntax to write CSS codes
element {
property:value ;
propety:value ;
}
Invented by invented by Brendan Eich in 1995
JavaScript is used to control the HTML elements and their attributes
<html>
<body>
<h2>My First JavaScript</h2>
<button type="button"
onclick = "document
.getElementById('myPara')
.innerHTML = Date()">
Click me to display Date and Time.
</button>
<p id="myPara"> </p>
</body>
</html>
document.getElementById('myPara').innerHTML=Date()
JavaScript functions are written within script tags
<script> </script>
JavaScript can be embedded in both <head>
and <body>
tags
<body>
tag for page to load faster Recommended norm is to write script in an external file with .js extension and include it
<script src="myScript.js"></script>
Common HTML Events to invoke JavaScript functions
Event | Description |
---|---|
onchange | An HTML element has been changed |
onclick | The user clicks an HTML element |
onmouseover | The user moves the mouse over an HTML element |
onmouseout | The user moves the mouse away from an HTML element |
onkeydown | The user pushes a keyboard key |
onload | The browser has finished loading the page |
<html>
<head>
<script>
function makeRed(x) {
x.style.color='red';
}
function makeBlue(x) {
x.style.color='blue';
}
</script>
</head>
<body>
<h1 id ='myHeader'
onmouseover = "makeRed(this)"
onmouseout = "makeBlue(this)"
onclick = "alert('Holla !')">
Mouse over me
</h1>
</body>
</html>
For most common scripting languages please visit
http://www.w3schools.com/default.asp
To learn more about HTML and how it works with examples please visit
http://www.w3schools.com/html/
To test your HTML and JavaScript codes you may like to use
http://jsfiddle.net/