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;

How to get host name in JavaScript?


To get host name in JavaScript -
HTTP_HOST

var hostname = window.location.hostname


Friday, June 13, 2008

Size attribute in CSS


Relative Units


em
ems, the height of the element's font

ex x-height, the height of the letter "x"
px pixels, relative to the canvas resolution


Absolute Units

in
inches; 1 inch = 2.54cms

cm centimeters; 1cm = 10mm
mm millimeters
pt points; 1pt = 1/72 inch
pc picas; 1pc = 12pts

How to get client information in JavaScript...???


How to gather information about your users environment including their computer platform, operating system, browser details, etc. ?

Application Code Name
var codeName = navigator.appCodeName;

Application Name
var appName = navigator.appName;

Application Version

var appVersion = navigator.appVersion;

User Language and Language

var userLanguage = navigator.userLanguage;
var language = navigator.language;

Platform

var appName = navigator.platform;

User Agent

var userAgent = navigator.userAgent;

Java Enabled

var javaEnabled = navigator.javaEnabled();

To check cookies are enabled in the browser.
navigator.cookieEnabled

CPU class of the browser's system
var cpuClass = navigator.cpuClass;

To get boolean status of system mode.
navigator.onLine;

Browser Version

var version = parseInt(navigator.appVersion,10);


Wednesday, June 11, 2008

Disable Page Printing...


This is a Microsoft only solution and you should include these Attributes in your BODY Tag...

<body onBeforePrint="document.body.style.display='none'"; onAfterPrint="document.body.style.display='';">

This is a CSS cross-browser solution which should be included as a separate section in the HEAD of your page...
<style media='print'>
BODY { display:none;}
</style>

Disable Browser Cache...


Include this META Tag in the HEAD section of your page along with the other META Tags...
microsoft/mozilla/netscape browsers all require this meta tag
<meta http-equiv='Pragma' content='no-cache'>
microsoft browsers require this additional meta tag as well
<meta http-equiv='Expires' content='-1'>

and then include this second HEAD section between the BODY closing Tag and HTML closing Tag...
add this extra head section if you find your pages are still being cached in some browsers
</body>
<head>
<meta http-equiv='Pragma' content='no-cache'>
</head>
</html>

JavaScript Disabled...

Add this Markup to the HEAD section of your page, immediately below the META Tags ...

If JavaScript Disabled page will be redirected to given URL

<noscript>
<meta http-equiv='REFRESH' content='0;URL=redirect-error-page.html'>
</noscript>

Disable Copy/Paste ...


Add these attributes to the BODY Tag to disable copy/paste everywhere on the page...

<body ondragstart='return false' onselectstart='return false'>

or better still add this script to the JavaScript section in the HEAD of your page...
" document.body.ondragstart = 'return false' ; "
" document.body.onselectstart = 'return false'; "

Disable Image Toolbar


Use this Markup to disable Image Toolbar for all images on the page ...
<meta http-equiv='imagetoolbar' content='no'>

Use this Markup to disable Image Toolbar for individual images ...
<img src='imagename.gif' width='250' height='250' galleryimg='no'>

Disable Right Click


Add this attribute to the BODY Tag to disable the context menu everywhere on the page ...
<body oncontextmenu='return false'>

Add this Attribute to an IMG Tag to disable the context menu for individual images ...

<img src='imagename.gif' width='250' height='250' oncontextmenu='return false'>

Tuesday, June 10, 2008

Download Ajax Modules


Link to download mini Ajax Modules...


http://miniajax.com/

Monday, June 9, 2008

Welcome...!!!

Thanks a lot for your visit.