Showing posts with label JS. Show all posts
Showing posts with label JS. Show all posts

Tuesday, May 4, 2010

To get hash '#' ID from URL using Javascript


To get hash '#' ID from URL


< script type="text/javascript" >
if( window.location.hash ) {
var str = window.location.hash;
var str_split = str.split("#");
var getid = str_split[1];
}

< /script >

Monday, January 18, 2010

jQuery 1.4 Released

jQuery 1.4 Released Download

Wednesday, January 13, 2010

jQuery UI Multiselect

Plugin: jQuery UI Multiselect

Features :

  • Search within available options, if there are a lots of them
  • Displaying counts of selected and available items
  • Select All / Deselect All Buttons
  • Dragging items from the available list to the selected list directly

Tuesday, August 25, 2009

How to get Browser Window Size?

How to get Browser Window Size?

function getBroWinSize() {

var objDocEle = document.documentElement;
var objDocBdy = document.body;
var myWidth = 0, myHeight = 0;

if( typeof( window.innerWidth ) == 'number' ) { //Non-IE
myWidth = window.innerWidth;
myHeight = window.innerHeight;
}

else if(objDocEle &&(objDocEle.clientWidth || objDocEle.clientHeight)) { //IE 6+
myWidth = objDocEle.clientWidth;
myHeight = objDocEle.clientHeight;
}

else if(objDocBdy &&(objDocBdy.clientWidth || objDocBdy.clientHeight)){ //IE 4
myWidth = objDocBdy.clientWidth;
myHeight = objDocBdy.clientHeight;
}

window.alert( 'Width = ' + myWidth );
window.alert( 'Height = ' + myHeight );

}//
getBroWinSize

Tuesday, August 18, 2009

Javascript Libraries

Javascript Libraries

http://javascriptlibraries.com/

What is JavaScript library?

What is JavaScript library?

A JavaScript library is a library of pre-written JavaScript controls which allow for easier development of JavaScript-based applications, especially for AJAX and other web-centric technologies. (eg:- JQuery, Mybic...)

Sunday, August 16, 2009

Suppress JavaScript error

Code to Suppress JavaScript error


<SCRIPT language="JavaScript">

<!--
function suppressJSError() {
return true;
}
window.onerror=suppressJSError;
//-->

</SCRIPT>

Tuesday, January 6, 2009

jQuery Alert Dialogs


jQuery Alert Dialogs (Alert, Confirm, & Prompt Replacements)

jQuery Alert Dialogs

Wednesday, December 17, 2008

CSS Browser detection using jQuery


CSS Browser detection using jQuery instead of hacks

CSS Browser detection

Thursday, July 10, 2008

Date Object in JavaScript

Date Object in JavaScript

Method Description
Date() Returns today's date and time
getDate() Returns the day of the month from a Date object (from 1-31)
getDay() Returns the day of the week from a Date object (from 0-6)
getMonth() Returns the month from a Date object (from 0-11)
getFullYear() Returns the year, as a four-digit number, from a Date object
getYear() Returns the year, as a two-digit or a three/four-digit number, depending on the browser. Use getFullYear() instead !!
getHours() Returns the hour of a Date object (from 0-23)
getMinutes() Returns the minutes of a Date object (from 0-59)
getSeconds() Returns the seconds of a Date object (from 0-59)
getMilliseconds() Returns the milliseconds of a Date object (from 0-999)
getTime() Returns the number of milliseconds since midnight Jan 1, 1970
getTimezoneOffset() Returns the difference in minutes between local time and Greenwich Mean Time (GMT)
getUTCDate() Returns the day of the month from a Date object according to universal time (from 1-31)
getUTCDay() Returns the day of the week from a Date object according to universal time (from 0-6)
getUTCMonth() Returns the month from a Date object according to universal time (from 0-11)
getUTCFullYear() Returns the four-digit year from a Date object according to universal time
getUTCHours() Returns the hour of a Date object according to universal time (from 0-23)
getUTCMinutes() Returns the minutes of a Date object according to universal time (from 0-59)
getUTCSeconds() Returns the seconds of a Date object according to universal time (from 0-59)
getUTCMilliseconds() Returns the milliseconds of a Date object according to universal time (from 0-999)
parse() Takes a date string and returns the number of milliseconds since midnight of January 1, 1970
setDate() Sets the day of the month in a Date object (from 1-31)
setMonth() Sets the month in a Date object (from 0-11)
setFullYear() Sets the year in a Date object (four digits)
setYear() Sets the year in the Date object (two or four digits). Use setFullYear() instead !!
setHours() Sets the hour in a Date object (from 0-23)
setMinutes() Set the minutes in a Date object (from 0-59)
setSeconds() Sets the seconds in a Date object (from 0-59)
setMilliseconds() Sets the milliseconds in a Date object (from 0-999)
setTime() Calculates a date and time by adding or subtracting a specified number of milliseconds to/from midnight January 1, 1970
setUTCDate() Sets the day of the month in a Date object according to universal time (from 1-31)
setUTCMonth() Sets the month in a Date object according to universal time (from 0-11)
setUTCFullYear() Sets the year in a Date object according to universal time (four digits)
setUTCHours() Sets the hour in a Date object according to universal time (from 0-23)
setUTCMinutes() Set the minutes in a Date object according to universal time (from 0-59)
setUTCSeconds() Set the seconds in a Date object according to universal time (from 0-59)
setUTCMilliseconds() Sets the milliseconds in a Date object according to universal time (from 0-999)
toSource() Represents the source code of an object
toString() Converts a Date object to a string
toGMTString() Converts a Date object, according to Greenwich time, to a string. Use toUTCString() instead !!
toUTCString() Converts a Date object, according to universal time, to a string
toLocaleString() Converts a Date object, according to local time, to a string
UTC() Takes a date and returns the number of milliseconds since midnight of January 1, 1970 according to universal time

Tuesday, July 8, 2008

String Object in JavaScript

String Object in JavaScript

var str="Hello world!";

To get length of a string
var str_len = str.length;

To style strings
var str_big = str.big();
var str_small = str.small() ;
var str_bold = str.bold() ;
var str_italic = str.italics() ;
var str_blink = str.blink(); //(does not work in IE)
var str_fixed = str.fixed() ; //Displays a string as teletype text
var str_strike = str.strike() ;
var str_fc = str.fontcolor("Red") ;
var str_fs = str.fontsize(12) ;
var str_lc = str.toLowerCase() ;
var str_uc = str.toUpperCase() ;
var str_sub = str.sub() ;
var str_sup = str.sup() ;
var str_link = str.link("http://www.w3schools.com");

To get position of the first occurrence of a specified string value in a string
var str_pos = str.indexOf( "o" );

The lastIndexOf() method returns the position of the last occurrence of a specified string value, searching backwards from the specified position in a string.
var str_pos = str.lastIndexOf( "o" );

To use the match() method to search for a specified string value within a string and return the string value if found
var str_match = str.match( "world!" );

To use the replace() method to replace some characters with some other characters in a string.
var str_replace = str.replace( /world/, "JavaScript" );

The search() method is used to search a string for a specified value.
var str_search = str.search( /world/ );

The concat() method is used to join two or more strings.
var str_concat = str.concat("welcome", "to", "JavaScript");

The anchor() method is used to create an HTML anchor.
var str_anchor = str.anchor( "anchorName" );

The charAt() method returns the character at a specified position.
var str_charat = str.charAt( 1 ); //H

The charCodeAt() method returns the Unicode of the character at a specified position.
var str_charcode = str.charCodeAt( 1 ); //101

The fromCharCode() takes the specified Unicode values and returns a string.
var str_fromCharCode = String.fromCharCode( 72,69,76,76,79 ); //HELLO

The slice() method extracts a part of a string and returns the extracted part in a new string.
var str_slice = str.slice( 6 );

The split() method is used to split a string into an array of strings.
var str_split = str.split( " " );

The substr() method extracts a specified number of characters in a string, from a start index.
var str_substr = str.substr( 3 );

The substring() method extracts the characters in a string between two specified indices.
var str_substring = str.substring( 3 );

Wednesday, July 2, 2008

Regular Expression Patterns Examples

Regular Expression Patterns Examples...

http://regexlib.com/DisplayPatterns.aspx

Thursday, June 26, 2008

Math Object in JavaScript

Math Object in JavaScript

round() to round a number
Math.round(0.60) = 1;
Math.round(0.49) = 0;

random() to return a random number between 0 and 1
Math.random()

max() to return the number with the highest value of two specified numbers
Math.max(5,7) = 7
Math.max(-3,-5) = -3

min() to return the number with the lowest value of two specified numbers
Math.min(5,7) = 5
Math.max(-3,-5) = -5

Wednesday, June 18, 2008

Window Object in JavaScript


Window Object in JavaScript

Some Syntax...

To get default text in the statusbar of the window
var status = window.defaultStatus;

To get text in the statusbar of a window
var status = window.status;

To get window name
var winName = window.name;

To remove focus from the current window
window.blur();

To set focus to the current window
window.focus();

To get the outer height of a window in pixels
var outerheight= window.outerheight;

To get the outer width of a window in pixels
var outerwidth= window.outerwidth;

To get reference to the current window
window.self;

To get topmost ancestor window
window.top;

To moves a window a specified number of pixels relative to its current coordinates
window.moveBy(x,y);

To moves a window's left and top edge to the specified coordinates
window.moveTo(x,y);

To resize a window by the specified pixels
resizeBy(width,height);

To resize the window to the specified width and height
resizeTo(width,height);

To scroll the content by the specified number of pixels
scrollBy(xnum,ynum);

To scrolls the content to the specified coordinates
scrollTo(xpos,ypos);

To print the contents of the current window
window.print();

To open a new browser window
window.open(URL,name,specs,replace);

To close the current window
window.close();

To check window has been closed
var closed = window.closed;

Regular Expressions in JavaScript


Regular Expressions can be used in the following JavaScript String Methods.

  1. string.match()
  2. string.search()
  3. string.replace()
  4. string.split()

Trim in JavaScript


To Trim space in a word


Left Trim Function to trim the space in the left side of the string

function ltrim ( s ){
return s.replace( /^\s*/, "" );
}

Right Trim Function to trim the space in the right side of the string

function rtrim ( s ){
return s.replace( /\s*$/, "" );
}

Trim Function to trim the space in the string

function trim(s) {
var temp = s;
return temp.replace(/^\s+/,'').replace(/\s+$/,'');
}

Monday, June 16, 2008

Document Object in JavaScript


Document Objects in JavaScript


To write in document
document.write("Hello World!");
document.writeln("Hello World!");

The title of the document
var title = document.title;

The URL of this document
var url = document.URL;

The referrer of this document
var referrer = document.referrer;

The domain name for this document
var domain = document.domain;

To get element object by ID
var obj = document.getElementById("id_name");

To get element object by Name
var obj = document.getElementsByName("tag_name");

To get element object by TagName
var obj = document.getElementsByTagName("tag_name");

Number of anchors in this document
var cnt_anchor = document.anchors.length;

Number of Form in this document
var cnt_frm = document.forms.length;

Number of images in this document
var cnt_img = document.images.length;

The cookie property sets or returns all cookies associated with the current document.
var cookie = document.cookie;

The lastModified property returns the date and time the document was last modified.
var lastmodified = document.lastModified;

Screen Object in JavaScript


To detect details about the client's screen


Screen resolution:
document.write(screen.width + "*" + screen.height);

Available view area:
document.write(screen.availWidth + "*" + screen.availHeight);

Color depth:
document.write(screen.colorDepth);

Buffer depth:
document.write(screen.bufferDepth);

DeviceXDPI:
document.write(screen.deviceXDPI);

DeviceYDPI:
document.write(screen.deviceYDPI);

LogicalXDPI:
document.write(screen.logicalXDPI);

LogicalYDPI:
document.write(screen.logicalYDPI);

FontSmoothingEnabled:
document.write(screen.fontSmoothingEnabled);

PixelDepth:
document.write(screen.pixelDepth);

UpdateInterval:
document.write(screen.updateInterval);

Events in JavaScript


What is Event in JavaScript...???


Every time anything happens to a page or an object in the page an event is triggered.

Here few examples of events.
  • onload
  • onChange
  • onMouseOver
  • onResize
  • onError
  • onUnload
  • onSubmit
  • onAbort
  • onClick
and etc...

We can use these events to trigger our scripts, or more correctly, to trigger a function.

Sunday, June 15, 2008

How to get window title in JavaScript...???


To Get Window Title in JavaScript


var title = document.title;