function setCookie (name, value, expires, path, domain, secure){
var today = new Date();
today.setTime(today.getTime());
if (expires){
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires));
document.cookie = name+'='+escape( value ) +
((expires) ? ';expires='+expires_date.toGMTString() : '' ) + //expires.toGMTString()
((path) ? ';path=' + path : '' ) +
((domain) ? ';domain=' + domain : '' ) +
((secure) ? ';secure' : '' );
}
function getCookie(name){
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ((!start) && (name != document.cookie.substring( 0, name.length))){
return null;
}
if (start == -1) return null;
var end = document.cookie.indexOf(';', len);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(len, end));
}
function deleteCookie (name, path, domain){
if (getCookie(name)) document.cookie = name + '=' +
((path) ? ';path=' + path : '') +
((domain) ? ';domain=' + domain : '' ) +
';expires=Thu, 01-Jan-1970 00:00:01 GMT';
}
Ext.apply is a Sencha function to copy objects. Ext.apply(, );
You can have multiple source object names separated by comma.
Why do we need Ext.apply? Isn’t = enough? No, its not. Not only because you can merge and copy multiple sources to the destination there is also the big reason that, just a simple ‘=’ copies only the reference of the source object to the destination. Which means that if, you make any change to the destination object after copy it will affect the source copy too!
You can format numbers in javascript in following way:
var num = 12; var dec = 2; // decimal part rounded to 2var fomatedNumber = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec); alert(fomatedNumber) ; num = 45.6739; var fomatedNumber = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec); alert(fomatedNumber) ;
That’s it.
In-order to detect an orientation change on an Android browser, add a listener for either the ‘orientationchange’ or ‘resize’ event on window.
// Detect whether device supports orientationchange event, otherwise fall back to the resize event.
var supportsOrientationChange = "onorientationchange" in window,
orientationEvent = supportsOrientationChange ? "orientationchange" : "resize";
window.addEventListener(orientationEvent, function() {
alert('Rotation of screen:' + window.orientation + " " + screen.width);
}, false);
You can then check the window.orientation property to figure out which way the device is oriented. With Android phones, screen.width or screen.height also updates as the device is rotated. This will not work in the case with the iPhone, because orientation change does not update screen.width or screen.height.
Replace String Function in Javascript is used to replace the specified characters with new characters in the provided string.
Syntax:
stringObject.replace([string pattern to find],[new string]);
Example:
var myString = new String(); myString = "This is first example"; document.write(myString.replace(/ /,"-"));
Above example will replace the first occurrence of space with hyphen “-”.
Output: This-is first example
Split Function in JavaScript is used to split any string into two or more parts by passing the separator character in the split function. Split function splits a string into an array by storing the first part at first index, second part at second index and so on.
Syntax:
stringObject.split( [separator character] );
example:
<pre class=”brush:js”>
<script type=”text/javascript” language=”javascript”>
var myArr = new Array();
var myString = new String();
myString = “1,2,3,4,5,6,7,8,9″;
myArr = myString.split(“,”);
for(var i=0;i<myArr.length;i++)
{
document.write(“Array Index ” + i + ” = ” + myArr[i] + “<br />”);
}
</script>
</pre>
<html>
<script language="JavaScript" type="text/javascript">
String.prototype.trim = function ()
{
return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
var s = new String(" Hello ");
s=s.trim();
alert("!" + s + "!");
</script>
</html>






