Parsing custom formatted date string into Date object using SimpleDateFormat

This example shows how to parse string containing date and time in custom formats into Date object using Java SimpleDateFormat class.

import java.util.Date;
import java.text.ParseException;
import java.text.SimpleDateFormat;

public class ParsingCustomFormatDate {

public static void main(String[] args) {

//create object of SimpleDateFormat class with custom format
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yy");

try
{
//parse string containing specified format into date object
Date date = sdf.parse("11/10/14");
System.out.println(date);
}
catch(ParseException pe)
{ 
System.out.println("Parse Exception : " + pe);
}
  }
}

A simple JDBC application sample code

The basic process for a single data retrieval operation using JDBC would be as follows.
  • a JDBC driver would be loaded;
  • a database Connection object would be created from using the DriverManager (using the database driver loaded in the first step);
  • a Statement object would be created using the Connection object;
  • a SQL Select statement would be executed using the Statement object, and a ResultSet would be returned;
  • the ResultSet would be used to step through (or iterate through) the rows returned and examine the data.
The following JDBC code sample demonstrates this sequence of calls.
import java.sql.* 

public class JDBCSample { 
public static void main( String args[]) { 

String connectionURL = "jdbc:postgresql://localhost:5432/movies;user=java;password=samples"; 

// Change the connection string according to your db, ip, username and password 

try { 

// Load the Driver class. 

Class.forName("org.postgresql.Driver"); 

// If you are using any other database then load the right driver here. 

//Create the connection using the static getConnection method 

Connection con = DriverManager.getConnection (connectionURL); 

//Create a Statement class to execute the SQL statement 

Statement stmt = con.createStatement(); 

//Execute the SQL statement and get the results in a Resultset 

ResultSet rs = stmd.executeQuery("select moviename, releasedate from movies"); 

// Iterate through the ResultSet, displaying two values 

// for each row using the getString method 

while (rs.next()) 

System.out.println("Name= " + rs.getString("moviename") + " Date= " + rs.getString("releasedate"); 

} 

catch (SQLException e) { 

e.printStackTrace(); 

} 

catch (Exception e) { 

 e.printStackTrace(); 

} 

finally { 

// Close the connection 

con.close(); 

} 

} 

} 

The History of AJAX

In the beginning, there was the World Wide Web. Compared with desktop applications, web applications were slow and clunky. People liked web applications anyway because they were conveniently available from anywhere, on any computer that had a browser. Then Microsoft created XMLHttpRequest in Internet Explorer 5, which let browser-side JavaScript communicate with the web server in the background without requiring the browser to display a new web page. That made it possible to develop more fluid and responsive web applications. Mozilla soon implemented XMLHttpRequest in its browsers, as did Apple (in the Safari browser) and Opera.

XMLHttpRequest must have been one of the Web's best kept secrets. Since its debut in 1998, few sites have used it at all, and most developers, if they even knew about it, never used it. Google started to change that when it released a series of high-profile web applications with sleek new UIs powered by XMLHttpRequest. The most visually impressive of these is Google Maps, which gives you the illusion of being able to drag around an infinitely sizable map in its little map window.

While Google's prominent use of XMLHttpRequest dramatically demonstrated that vastly improved UIs for web apps were possible, it was Jesse James Garrett's February 18 essay that finally gave this technique a usable name: Ajax (Asynchronous JavaScript and XML). That was the tipping point. Without knowing it, we as an industry had been waiting for this, and the new Ajax name spread like wildfire. I have never seen such rapid and near universal adoption of a new technology moniker!


Using revealTrans to do page transitions in Javascript

Here are some page transitions to amaze your visitors. All you have to do is add a new meta tag to the <HEAD> section of your page:

<META http-equiv="Page-Enter" content="revealTrans(Duration=5,Transition=17)">

That's all there is to it! In the above code, the time it takes to transition is five seconds and the transition effect is #17. Below is a list of all available transition effects.

0 - Shrinking Box
1 - Growing Box
2 - Shrinking Circle
3 - Growing Circle
4 - Wipes Up
5 - Wipes Down
6 - Wipes Right
7 - Wipes Left
8 - Right-Moving Stripes
9 - Downward-Moving Stripes
10 - Right-Moving Boxes
11 - Downward-Moving Boxes
12 - Dissolve Screen
13 - Horizontal Curtain Closing
14 - Horizontal Curtain Opening
15 - Vertical Curtain Closing
16 - Vertical Curtain Opening
17 - Left-Down Wipe
18 - Left-Up Wipe
19 - Right-Down Wipe
20 - Right-Up Wipe
21 - Horizontal Bars Dissolve Screen
22 - Vertical Bars Dissolve Screen
23 - Random Effect, for the adventurous!

There you have it. Netscape will ignore these tags, but visitors using Internet Explorer (far and away the majority), will see nifty transition effects.
Using revealTrans to do page transitions in Javascript

Scrolling message on the status bar using Javascript

If you are looking for a simple java script to show a scrolling message on the status bar then you can use this script.

TWO STEPS TO INSTALL WRITE AND SLIDE

  1. Paste the coding into the HEAD of your HTML document
  2. Copy the onLoad event handler into the BODY tag

STEP ONE: Copy this code into the HEAD of your HTML document

<SCRIPT LANGUAGE="JavaScript"> <!-- Begin

var Message="Yet another simple scroll!";

var place=1;

function scrollIn() {

window.status=Message.substring(0, place);

if (place >= Message.length) {

place=1;

window.setTimeout("scrollOut()",300);

} else {

place++;

window.setTimeout("scrollIn()",50);

}

}

function scrollOut() {

window.status=Message.substring(place, Message.length);

if (place >= Message.length) {

place=1;

window.setTimeout("scrollIn()", 100);

} else {

place++;

window.setTimeout("scrollOut()", 50);

}

}

// End -->

</SCRIPT> 


STEP TWO: Add this onLoad() event handler into the BODY tag

<BODY onLoad="scrollIn()"> 


Scrolling message on the status bar using Javascript

Getting Browser's height and width using Javascript

Getting the Browser's height and width is quite useful in many circumstances. For example if you are using a google map in your site, you will have to set a height and width for the map object. But the problem is there are so many different types of browsers out there and you don't know which one the end user will be using. Another issue is the height and the width of different laptops and desktops available in the market.

So most probably you are fine tuning your application based on the server or the PC or the laptop that you are using to develop. It will look perfectly fine until one day you decide to demo to your colleagues using a different laptop. All the layouts and alignments will be wrong. This happens if you hard code the height and width of the objects that you require in your site.

The best way for such applications is to get the height and the width of the client dynamically (using javascript) and then setting the height and the width of the objects dynamically. You can use the following javascript example to get the height and the width of the client.

JavaScript Code to get browser height and width

var myHeight;

if( typeof( window.innerWidth ) == 'number' ) {

//Non-IE

myWidth = window.innerWidth;
myHeight = window.innerHeight;

} else if( document.documentElement &&

( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {

//IE 6+ in 'standards compliant mode'

myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;

} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {

//IE 4 compatible

myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;

} 


In my case I had to use a google map in my site, therefore I used this code and then set the height and the width of the google map dynamically as follows:

Setting the google map height and width Dynamically using Javascript:
document.getElementById("map").style.height = myHeight+'px';
document.getElementById("map").style.width = myWidth+'px';

Getting Browser's height and width using Javascript

Disabling Right Click option in a browser using Javascript

There are two ways you can disable the 'Right Click' option on a browser's window. These get placed in the <HEAD> of your web page.

First, the easy one:

<SCRIPT>

function click() 

{

if (event.button==2) 

    {    

        alert('Your Warning Message Line 1 here\nYour Warning Message Line 2 here\nYour Warning Message Line 3 here\nYour Warning Message Line 4 here');

    }

}document.onmousedown=click

// - ->

</SCRIPT> 



Second Approach :

This script works in Internet Explorer and Netscape 6: 

<SCRIPT LANGUAGE="JavaScript1.1">

<!-- Begin

function right(e) {

var msg = "Right-clicking is not possible in this document.";

if (navigator.appName == 'Netscape' && e.which == 3) {

alert(msg); 

return false;

}

else

if (navigator.appName == 'Microsoft Internet Explorer' &&

event.button==2) {

alert(msg); 

return false;

}

return true;

}

document.onmousedown = right;

// End -->

</SCRIPT>  



Disabling Right Click option in a browser using Javascript

Program to read a file line by line in Java

This sample Java program demonstrates how to read a file in Java Line by Line. For this the following two classes DataInputStream and BufferedReader are used. This program can be used to read any text file line by line and process the contents of the file within a Java Program.

Class DataInputStream :

A data input stream is use to read primitive Java data types from an underlying input stream in a machine-independent way. An application uses a data output stream to write data that can later be read by a data input stream.

BufferedReader

Read text from a character-input stream, buffering characters so as to provide for the efficient reading of characters, arrays, and lines.

The buffer size may be specified, or the default size may be used. The default is large enough for most purposes.

In general, each read request made of a Reader causes a corresponding read request to be made of the underlying character or byte stream. It is therefore advisable to wrap a BufferedReader around any Reader whose read() operations may be costly, such as FileReaders and InputStreamReaders. For example,
BufferedReader in = new BufferedReader(new FileReader("foo.in"));


will buffer the input from the specified file. Without buffering, each invocation of read() or readLine() could cause bytes to be read from the file, converted into characters, and then returned, which can be very inefficient.

Programs that use DataInputStreams for textual input can be localized by replacing each DataInputStream with an appropriate BufferedReader.

Java Program to read file using BufferedReader

import java.io.*;
class FileRead 
{
   public static void main(String args[])
  {
      try{
    // Open the file that is the first 
    // command line parameter
    FileInputStream fstream = new FileInputStream("textfile.txt");
    // Get the object of DataInputStream
    DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;
    //Read File Line By Line
    while ((strLine = br.readLine()) != null)   {
      // Print the content on the console
      System.out.println (strLine);
    }
    //Close the input stream
    in.close();
    }catch (Exception e){//Catch exception if any
      System.err.println("Error: " + e.getMessage());
    }
  }
}

Program to read a file line by line in Java

Program to write to a file in Java

This sample Java program demonstrates how to write to a file in Java. For this, the following two classes FileWriter and BufferedWriter are used. This program can be used to write to any text file using a Java Program.

FileWriter

The FileWriter is a class used for writing character files. The constructors of this class assume that the default character encoding and the default byte-buffer size are acceptable. To specify these values yourself, construct an OutputStreamWriter on a FileOutputStream.

BufferedWriter

The BufferWriter class is used to write text to a character-output stream, buffering characters so as to provide for the efficient writing of single characters, arrays, and strings.

Program to write to a file in java

import java.io.*;
class FileWrite 
{
   public static void main(String args[])
  {
      try{
    // Create file 
    FileWriter fstream = new FileWriter("out.txt");
        BufferedWriter out = new BufferedWriter(fstream);
    out.write("Hello Java");
    //Close the output stream
    out.close();
    }catch (Exception e){//Catch exception if any
      System.err.println("Error: " + e.getMessage());
    }
  }
}
Program to write to a file in Java

Program to execute system commands in a Java

Most often in your Java programs you will find a need to execute system DOS commands. You can execute any system commands that are OS specific and then read the output of the system command from your Java program for further processing within the Java program.

This sample Java Program executes the 'dir' command reads the output of the dir command prints the results. This is just for understanding the concept, however, you may execute just about any command using this Runtime.getRuntime().exec() command.

Program to execute system commands in a Java

import java.io.*; 
public class TestCMD 
{ 
public static void main(String args[]) 
{ 
try 
{ 
Process p=Runtime.getRuntime().exec("cmd /c dir"); 
p.waitFor(); 
BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream())); 
String line=reader.readLine(); 
while(line!=null) 
{ 
System.out.println(line); 
line=reader.readLine(); 
} 
} 
catch(IOException e1) {} 
catch(InterruptedException e2) {} 

System.out.println("Done"); 
} 
} 

Program to execute system commands in a Java

Short-Circuit Logical Operator In Java

Java provides two interesting Boolean operators not found in most other computer languages. These are secondary versions of the Boolean AND and OR operators, and are known as short-circuit logical operators.

As you can see from the preceding table, the OR operator results in true when A is true, no matter what B is. Similarly, the AND operator results in false when A is false, no matter what B is. If operator results in false when A is false, no matter what B is.

If you use the | | and && forms, rather than the | and & forms of these operators, java will not bother to evaluate the right-hand operand alone. This is very useful when the right-hand operand depends on the left one being true or false in order to function properly.

For example, the following code fragment shows how you can take advantage of short-circuit logical evaluation to be sure that a division operation will be valid before evaluating it:

if ( denom != 0 && num / denom >10) 

Since the short-circuit form of AND (&&) is used, there is no risk of causing a run-time exception when denom is zero. If this line of code were written using the single & version of AND, both sides would have to be evaluated, causing a run-time exception when denom is zero.

It is standard practice to use the short-circuit forms of AND and OR in cases involving Boolean logic, leaving the single-character versions exclusively for bitwise operations. However, there are exceptions to this rule. For example, consider the following statement:

if ( c==1 & e++ < 100 ) d = 100; 

Here, using a single & ensures that the increment operation will be applied to e whether c is equal to 1 or not.
Short-Circuit Logical Operator In Java

How to get List of stored procedures in SQL Server

This post is about sp_stored_procedures which is used to get a list of stored procedures in a SQL Server database.

The simplest way to use sp_stored_procedures is to call it with no arguments:
exec sp_stored_procedures

This will return a complete list of stored procedures for the MS SQL Server database use are currently using. Example output from the above is as follows:
PROCEDURE_QUALIFIERPROCEDURE_OWNERPROCEDURE_NAMENUM_INPUT_PARAMSNUM_OUTPUT_PARAMSNUM_RESULT_SETSREMARKSPROCEDURE_TYPE
MyDbdboFoo;1-1-1-12
MyDbdboBar;1-1-1-12

The PROCEDURE_QUALIFIER column indicates which database the stored procedure belongs to; PROCEDURE_OWNER is the owner; PROCEDURE_NAME is the name of the stored procedure; NUM_INPUT_PARAMS, NUM_OUTPUT_PARAMS and NUM_RESULT_SETS are reserved for future use, according to the MSDN documentation; REMARKS always returns empty; PROCEDURE_TYPE always returns 2.

So as you can see most of the data returned is fairly useless, being reserved for "future use" or always returning the same value. However getting the list of procedure names is of course useful!

The sp_stored_procedures stored procedure also takes 4 optional parameters:

@sp_name - if specified it will return just the stored procedure name specified. Wildcard pattern matching with _ [ ] and % is supported, so you can do the following, for example, to just return stored procedures starting with "a":

exec sp_stored_procedures 'a%'
OR
exec sp_stored_procedures @sp_name = 'a%'

@sp_owner - allows you to list stored procedures only belonging to a particular owner. As with the @sp_name parameter it supports wildcard matching with % [ ] and _

@qualifier - allows you to specify which database to list stored procedures for.

@fUsePattern - specifies whether wildcard matching is on or off. If set to 1 then wildcard matching is on (the default) and if 0 then wildcard matching is switched off.

List stored procedures with MS SQL Server

How to get list of tables in SQL Server

sp_tables returns a list of tables and views that can be queried in a selected database. The basic usage is as follows:
sp_tables [ [ @table_name = ] 'name' ]
     [ , [ @table_owner = ] 'owner' ]
     [ , [ @table_qualifier = ] 'qualifier' ]
     [ , [ @table_type = ] "type" ]
     [ , [@fUsePattern = ] 'fUsePattern'];

On its own, calling "exec sp_tables" will simply list all the tables and views for the current database, as shown in the following example resultset:
TABLE_QUALIFIER TABLE_OWNER TABLE_NAME TABLE_TYPE REMARKS
MyDBName dbo ExampleTable1 TABLE
MyDBName dbo ExampleTable1 TABLE

You can use the @table_name @table_owner and @table_qualifier parameters with wildcards to return a smaller resultset. @table_name queries the table names, @table_owner the owners and @table_qualifier the database name. For example, to only return tables which start with the letter "a" you could execute either of these:
EXEC sp_tables "a%";
EXEC sp_tables @table_name = "a%";

The @table_type parameter lets you specify whether tables, system tables and/or views should be returned. If not specified then it will return all of them. To use this parameter, the values are a single quote and comma separated list inside double quotes, as shown in the following example:

EXEC sp_tables @table_type = "'view'";

EXEC sp_tables @table_type = "'table', 'view'";The @fUsePattern allows you to specify whether _ % and [ ] characters are interpreted as wildcard characters or not. If set to 0 then pattern matching is switched off and those characters must be present in the table name etc to be returned. If set to 1 (or not specified - the default is on) then wildcard pattern matching is switched off.
How to get list of tables in SQL Server

How To describe table structure in SQL Server

This post is about sp_columns which is used to describe the table structure of a SQL Server table.
The simplest way to use sp_columns to show the columns and related information about a SQL Server table is to execute the stored proecedure passing it the table name like so:

exec sp_columns MyTable

This returns a row for each column in the table, describing the column in detail.

The sp_columns stored procedure can take additional arguments to the table name. You can also pass the table owner, table qualifier (i.e. the database name), column name and the ODBC version used. The table owner and column name parameters support wildcard pattern matching, so you can use % and _

For example, if you only wanted to query the "foo" column from the above example, you would do this:

exec sp_columns MyTable, @column_name = 'foo'

If you wanted to query all columns which started with the letter "a" you could do the following:

exec sp_columns MyTable, @column_name = 'a%'
How To describe table structure in SQL Server

HTML5 : Form Input Elements

Apart from the above mentioned attributes, HTML5 input elements introduced several new values for the type attribute. These are listed below.
NOTE: Try the entire following example using latest version of Opera browser.
Type
Description
text
A free-form text field, nominally free of line breaks.
password
A free-form text field for sensitive information, nominally free of line breaks.
checkbox
A set of zero or more values from a predefined list.
radio
An enumerated value.
submit
A free form of button initiates form submission.
file
An arbitrary file with a MIME type and optionally a file name.
image
A coordinate, relative to a particular image's size, with the extra semantic that it must be the last value selected and initiates form submission.
hidden
An arbitrary string that is not normally displayed to the user.
select
An enumerated value, much like the radio type.
textarea
A free-form text field, nominally with no line breaks restrictions.
button
A free form of button which can initiate any event related to button.

Following is the simple example of using labels, radio buttons, and submit buttons:
...
<form action="http://example.com/cgiscript.pl" method="post">
    <p>
    <label for="firstname">first name: </label>
              <input type="text" id="firstname"><br />
    <label for="lastname">last name: </label>
              <input type="text" id="lastname"><br />
    <label for="email">email: </label>
              <input type="text" id="email"><br>
    <input type="radio" name="sex" value="male"> Male<br>
    <input type="radio" name="sex" value="female"> Female<br>
    <input type="submit" value="send"> <input type="reset">
    </p>
 </form>
 ...

The <input> element in HTML5:

Apart from the above mentioned attributes, HTML5 input elements introduced several new values for the type attribute. These are listed below.
NOTE: Try the entire following example using latest version of Opera browser.
Type
Description
datetime
A date and time (year, month, day, hour, minute, second, fractions of a second) encoded according to ISO 8601 with the time zone set to UTC.
datetime-local
A date and time (year, month, day, hour, minute, second, fractions of a second) encoded according to ISO 8601, with no time zone information.
date
A date (year, month, day) encoded according to ISO 8601.
month
A date consisting of a year and a month encoded according to ISO 8601.
week
A date consisting of a year and a week number encoded according to ISO 8601.
time
A time (hour, minute, seconds, fractional seconds) encoded according to ISO 8601.
number
This accepts only numerical value. The step attribute specifies the precision, defaulting to 1.
range
The range type is used for input fields that should contain a value from a range of numbers.
email
This accepts only email value. This type is used for input fields that should contain an e-mail address. If you try to submit a simple text, it forces to enter only email address in email@example.com format.
url
This accepts only URL value. This type is used for input fields that should contain a URL address. If you try to submit a simple text, it forces to enter only URL address either in http://www.example.com format or in http://example.com format.

The <output> element:

HTML5 introduced a new element <output> which is used to represent the result of different types of output, such as output written by a script.
You can use the for attribute to specify a relationship between the output element and other elements in the document that affected the calculation (for example, as inputs or parameters). The value of the for attribute is a space-separated list of IDs of other elements.
The placeholder attribute:

HTML5 introduced a new attribute called placeholder. This attribute on <input> and <textarea> elements provides a hint to the user of what can be entered in the field. The placeholder text must not contain carriage returns or line-feeds.
Here is the simple syntax for placeholder attribute:
<input type="text" name="search" placeholder="search the web"/>

This attribute is supported by latest versions of Mozilla, Safari and Chrome browsers only.
The autofocus attribute:

This is a simple one-step pattern, easily programmed in JavaScript at the time of document load, automatically focus one particular form field.
HTML5 introduced a new attribute called autofocus which would be used as follows:
<input type="text" name="search" autofocus/>

This attribute is supported by latest versions of Mozilla, Safari and Chrome browsers only.
The required attribute:

Now you do not need to have JavaScript for client side validations like empty text box would never be submitted because HTML5 introduced a new attribute called required which would be used as follows and would insist to have a value:
<input type="text" name="search" required/>

This attribute is supported by latest versions of Mozilla, Safari and Chrome browsers only.



HTML5 Events

Below are the global event attributes that can be added to HTML5 elements to define event actions.
Window Events :
Events triggered for the window object (applies to the <body> tag):
Attribute
Value
Description
Onafterprint
script
Script to be run after the document is printed
onbeforeprint
script
Script to be run before the document is printed
Onbeforeunload
script
Script to be run before the document is unloaded
onerror
script
Script to be run when an error occur
onhaschange
script
Script to be run when the document has changed
onload
script
Fires after the page is finished loading
onmessage
script
Script to be run when the message is triggered
onoffline
script
Script to be run when the document goes offline
ononline
script
Script to be run when the document comes online
onpagehide
script
Script to be run when the window is hidden
onpageshow
script
Script to be run when the window becomes visible
onpopstate
script
Script to be run when the window's history changes
onredo
script
Script to be run when the document performs a redo
onresize
script
Fires when the browser window is resized
onstorage
script
Script to be run when a Web Storage area is updated
onundo
script
Script to be run when the document performs an undo
onunload
script
Fires once a page has unloaded (or the browser window has been closed)


Form Events :

Events triggered by actions inside a HTML form (applies to almost all HTML5 elements, but is most used in form elements):
Attribute
Value
Description
onblur
script 
Fires the moment that the element loses focus
onchange
script
Fires the moment when the value of the element is changed
oncontextmenu
script 
Script to be run when a context menu is triggered
onfocus
script 
Fires the moment when the element gets focus
onformchange
script 
Script to be run when a form changes
onforminput
script 
Script to be run when a form gets user input
oninput
script 
Script to be run when an element gets user input
oninvalid
script 
Script to be run when an element is invalid
onreset
script 
Fires when the Reset button in a form is clicked
Not supported in HTML5
onselect
script 
Fires after some text has been selected in an element
onsubmit
script
Fires when a form is submitted


Keyboard Events :

Attribute
Value
Description
onkeydown
script 
Fires when a user is pressing a key
onkeypress
script 
Fires when a user presses a key
onkeyup
script 
Fires when a user releases a key


Mouse Events :

Events triggered by a mouse or similar user actions:
Attribute
Value
Description
onclick
script 
Fires on a mouse click on the element
ondblclick
script 
Fires on a mouse double-click on the element
ondrag
script 
Script to be run when an element is dragged
ondragend
script 
Script to be run at the end of a drag operation
ondragenter
script 
Script to be run when an element has been dragged to a valid drop target
ondragleave
script 
Script to be run when an element leaves a valid drop target
ondragover
script 
Script to be run when an element is being dragged over a valid drop target
ondragstart
script 
Script to be run at the start of a drag operation
ondrop
script 
Script to be run when dragged element is being dropped
onmousedown
script 
Fires when a mouse button is pressed down on an element
onmousemove
script 
Fires when the mouse pointer moves over an element
onmouseout
script
Fires when the mouse pointer moves out of an element
onmouseover
script
Fires when the mouse pointer moves over an element
onmouseup
script 
Fires when a mouse button is released over an element
onmousewheel
script 
Script to be run when the mouse wheel is being rotated
onscroll
script 
Script to be run when an element's scrollbar is being scrolled


Media Events :

Events triggered by Medias like videos, images and audio (applies to all HTML5 elements, but is most common in media elements, like audio, embed, img, object, and video):
Attribute
Value
Description
onabort
script 
Script to be run on abort
oncanplay
script
Script to be run when a file is ready to start playing (when it has buffered enough to begin)
oncanplaythrough
script
Script to be run when a file can be played all the way to the end without pausing for buffering
ondurationchange
script 
Script to be run when the length of the media changes
onemptied
script 
Script to be run when something bad happens and the file is suddenly unavailable (like unexpectedly disconnects)
onended
script 
Script to be run when the media has reach the end (a useful event for messages like "thanks for listening")
onerror
script 
Script to be run when an error occurs when the file is being loaded
onloadeddata
script
Script to be run when media data is loaded
onloadedmetadata
script
Script to be run when meta data (like dimensions and duration) are loaded
onloadstart
script
Script to be run just as the file begins to load before anything is actually loaded
onpause
script 
Script to be run when the media is paused either by the user or programmatically
onplay
script 
Script to be run when the media is ready to start playing
onplaying
script 
Script to be run when the media actually has started playing
onprogress
script 
Script to be run when the browser is in the process of getting the media data
onratechange
script 
Script to be run each time the playback rate changes (like when a user switches to a slow motion or fast forward mode)
onreadystatechange
script 
Script to be run each time the ready state changes (the ready state tracks the state of the media data)
onseeked
script 
Script to be run when the seeking attribute is set to false indicating that seeking has ended
onseeking
script 
Script to be run when the seeking attribute is set to true indicating that seeking is active
onstalled
script 
Script to be run when the browser is unable to fetch the media data for whatever reason
onsuspend
script
Script to be run when fetching the media data is stopped before it is completely loaded for whatever reason
ontimeupdate
script
Script to be run when the playing position has changed (like when the user fast forwards to a different point in the media)
onvolumechange
script
Script to be run each time the volume is changed which (includes setting the volume to "mute")
onwaiting
script
Script to be run when the media has paused but is expected to resume (like when the media pauses to buffer more data)