Search This Blog

Tuesday, 28 March 2017

మీకు మీ కుటుంబసభ్యులకు హేవిళంబి నామ ఉగాది శుభాకాంక్షలు!

🍋మామిడి పువ్వుకి మాట వచ్చింది🍋

🐦కోకిల గొంతుకు కుత వచ్చింది🐦

🌿వేప కొమ్మకు పూత వచ్చింది🌿

🍯పసిడి బెల్లం తోడు వచ్చింది🍯

🌿🌾గుమ్మానికి పచ్చని తోరణము వచ్చింది🌾🌿

🌾🍒పండగ మన ముందరికి వచ్చింది🍒🌾

🌾మీకు మీ కుటుంబసభ్యులకు హేవిళంబి నామ ఉగాది శుభాకాంక్షలు!🌾

Friday, 10 March 2017

Javascript::Check Type of JS Object

Check Type of JS Object

function objIs(type, obj) {
    var clas = Object.prototype.toString.call(obj).slice(8, -1);
    return obj !== undefined && obj !== null && clas === type;
}
 
objIs('String', 'test'); // true

objIs('String', new String('test')); // true

JavaScript::JavaScript ‘Back’ Button

JavaScript ‘Back’ Button

<a href="javascript:history.back(1)">Previous Page</a>

JavaScript::Get URL Parameter

Get URL Parameter
function getUrlParam(name) {
    var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
    return (results && results[1]) || undefined;

}

JavaScript::Browser Window Dimensions

Browser Window Dimensions

function report() { 
  document.getElementsByTagName('output')[0].innerHTML = 'screen.width:'+screen.width+'<br>screen.height:'+screen.height+'<br>window.innerWidth:'+window.innerWidth+'<br>window.innerHeight:'+window.innerHeight+'<br>window.outerWidth:'+window.outerWidth+'<br>window.outerHeight:'+window.outerHeight+'<br>document.documentElement.<br clientHeight:'+document.documentElement.clientHeight+'<br>window.devicePixelRatio:'+window.devicePixelRatio; 
}
window.addEventListener('load', report, false);
window.addEventListener('resize', report, false);
window.addEventListener('orientationchange', report, false);
window.addEventListener('deviceorientation', report, false);

window.addEventListener('MozOrientation', report, false);

JavaScript::Detecting Mobile Devices

Detecting Mobile Devices
var isMobile = {
  Android: function() {
    return navigator.userAgent.match(/Android/i);
  },
  BlackBerry: function() {
    return navigator.userAgent.match(/BlackBerry/i);
  },
  iOS: function() {
    return navigator.userAgent.match(/iPhone|iPad|iPod/i);
  },
  Opera: function() {
    return navigator.userAgent.match(/Opera Mini/i);
  },
  Windows: function() {
    return navigator.userAgent.match(/IEMobile/i);
  },
  any: function() {
    return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
  }
};
 
// Examples
if( isMobile.any() ) alert('Mobile');

if( isMobile.iOS() ) alert('iOS Device');

JavaScript::Detecting the Operating System

Detecting the Operating System

var system = navigator.appVersion;
if (navigator.appVersion.indexOf("Mac") != -1 ) OS = "Mac";
else if (navigator.appVersion.indexOf("PowerPC") != -1 ) OS = "Mac";
else if (navigator.appVersion.indexOf("Win") != -1 ) OS = "Win";
else if (navigator.appVersion.indexOf("SunOS") != -1 ) OS = "Solaris";
else  OS = "Linux";
 
//Determine Browser Version
bName = navigator.appName;
bVer  = parseInt(navigator.appVersion);
 
if (OS == "Mac" && bName=="Netscape") { 
  // your code here
}
else if (OS =="Mac" && bName=="Microsoft Internet Explorer") { 
  // your code here
}
else if (OS =="Win" || OS == "Linux" && bName == "Netscape") {
  // your code here
}
else if (OS =="Solaris" && bName=="Netscape") {
  // your code here
}
else if (OS =="Win" || OS == "Linux" && bName=="Microsoft Internet Explorer") {
  // your code here
}

JavaScript::JavaScript Cookies

JavaScript Cookies
function setCookie(name, value) {
  if(name != '')
    document.cookie = name + '=' + value;
}
 
function getCookie(name) {
  if(name == '')
    return('');
 
  name_index = document.cookie.indexOf(name + '=');
 
  if(name_index == -1)
    return('');
 
  cookie_value =  document.cookie.substr(name_index + name.length + 1, document.cookie.length);
 
  //All cookie name-value pairs end with a semi-colon, except the last one.
  end_of_cookie = cookie_value.indexOf(';');
  if(end_of_cookie != -1)
    cookie_value = cookie_value.substr(0, end_of_cookie);
 
  //Restores all the blank spaces.
  space = cookie_value.indexOf('+');
  while(space != -1) { 
    cookie_value = cookie_value.substr(0, space) + ' ' + 
    cookie_value.substr(space + 1, cookie_value.length);
 
    space = cookie_value.indexOf('+');
  }
 
  return(cookie_value);
}

JavaScript::Browser Detection

Browser Detection
// Internet Explorer
var ie  = document.all != null;  //ie4 and above
var ie5 = document.getElementById && document.all;
var ie6 = document.getElementById && document.all&&(navigator.appVersion.indexOf("MSIE>=0);
 
// Netscape
var ns4 = document.layers != null;
var ns6 = document.getElementById && !document.all;
var ns  = ns4 || ns6;
 
// Firefox
var ff  = !document.layers && !document.all;
 
// Opera
var op  = navigator.userAgent.indexOf("opera")>0;
var op7 = op && operaVersion() <= 7;
var op8 = op && operaVersion() >= 8;
 
// Detects the Opera version
function operaVersion() {
          agent = navigator.userAgent;
          idx = agent.indexOf("opera");       
          if (idx>-1) {
                    return parseInt(agent.subString(idx+6,idx+7));
          }

}

JavaScript::Obtain Select Input Value

Obtain Select Input Value
<select id="menulist">
  <option value="1">test1</option>
  <option value="2" selected="selected">test2</option>
  <option value="3">test3</option>
</select>
 
<script>
var e = document.getElementById("menulist");
var optvalue = e.options[e.selectedIndex].value; // the option value attribute
var opttext  = e.options[e.selectedIndex].text; // internal text inside option element
</script>

JavaScript::Detect When Browser is Closed

Detect When Browser is Closed
function checkBrowser() {
  // triggers on clicking the close button, Alt+F4 , File->Close 
  if(window.event.clientX < 0 && window.event.clientY < 0) {
    window.open("somefile.htmllosewindow",'left=12000,top=1200,width=120,height=50');
  }

}

JavaScript::JavaScript Cookies

JavaScript Cookies

<script type="text/javascript">
/**
* Sets a Cookie with the given name and value.
*
* name       Name of the cookie
* value      Value of the cookie
* [expires]  Expiration date of the cookie (default: end of current session)
* [path]     Path where the cookie is valid (default: path of calling document)
* [domain]   Domain where the cookie is valid
*              (default: domain of calling document)
* [secure]   Boolean value indicating if the cookie transmission requires a
*              secure transmission
*/                        
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}
</script>

<script type="text/javascript">
/**
* Gets the value of the specified cookie.
*
* name  Name of the desired cookie.
*
* Returns a string containing value of specified cookie,
*   or null if cookie does not exist.
*/
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}
</script>

<script type="text/javascript">
/**
* Deletes the specified cookie.
*
* name      name of the cookie
* [path]    path of the cookie (must be same as path used to create cookie)
* [domain]  domain of the cookie (must be same as domain used to create cookie)
*/
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}
</script>

It  will allow your site to store information on the viewer’s computer then read it at another point in time. This snippet can be used in many different ways to accomplish different tasks.

JavaScript::E-mail Validation

E-mail Validation

Head:
<script type="text/javascript">
function validateEmail(theForm) {
if (/^w+([.-]?w+)*@w+([.-]?w+)*(.w{2,3})+$/.test(theForm.email-id.value)){
return(true);
}
alert("Invalid e-mail address! Please enter again carefully!.");
return(false);
}
</script>
Body:
<form onSubmit="return validateEmail(this);" action="">
E-mail Address:
<input type="text" name="emailid" />
<input type="submit" value="Submit" />
<input type="reset" value="Reset" />
</form>

This snippet will validate that a properly formatted E-mail address is entered in a form, it cannot guarantee that the E-mail address is real, there is no way to check for that with JavaScript.

JavaScript::No Right-Click

No Right-Click

<script type="text/javascript">
function f1() {
  if(document.all) { return false; }
}
function f2(e) {
  if(document.layers || (document.getElementById &! document.all)) {
    if(e.which==2 || e.which==3) { return false; }
  }
}
if(document.layers) {
  document.captureEvents(Event.MOUSEDOWN);
  document.onmousedown = f1;
}
else {
  document.onmouseup = f2;
  document.oncontextmenu = f1;
}
document.oncontextmenu = new function("return false");
</script>

This snippet will prevent the viewer from being able to right-click on your page. This can discourage the average user from borrow images or code from your site.

JavaScript::Show Formatted Date

Show Formatted Date

Head:
<script type="text/javascript">
  function showDate() {
    var d = new Date();
    var curr_date = d.getDate();
    var curr_month = d.getMonth() + 1; //months are zero based
    var curr_year = d.getFullYear();
    document.write(curr_date + "-" + curr_month + "-" + curr_year);
  }
</script>
Body:
<script type="text/javascript">showDate();</script>

This snippet will allow you to display the current date anywhere on your webpage and does not need to be updated. Simply put it in place and forget about it.

JavaScript::Comma Separator

Comma Separator

Head:
<script type="text/javascript">
function addCommas(num) {
  num += ”;
  var n1 = num.split(‘.’);
  var n2 = n1[0];
  var n3 = n1.length > 1 ? ‘.’ + n1[1] : ”;
  var temp = /(d+)(d{3})/;
  while (temp.test(n2)) {
    n2 = n2.replace(temp, ” + ‘,’ + ”);
  }
  var out = return n2 + n3;
  document.write(out);
}
</script>
Body:
<script type="text/javascript">addCommas("4550989023");</script>

This snippet would be used mainly by sites that use numbers often. This snippet will keep your numbers looking the same across the board. All you have to do is copy the body line where you want to add a number and replace the number there with your number.

JavaScript::Get the Display Area of a Browser

Get the Display Area of a Browser

<script type="text/javascript">
<!–
var viewportwidth;
var viewportheight;
// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
if (typeof window.innerWidth != ‘undefined’)
{
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
}
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
else if (typeof document.documentElement != ‘undefined’
     && typeof document.documentElement.clientWidth !=
     ‘undefined’ && document.documentElement.clientWidth != 0)
{
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
}
// older versions of IE
else
{
       viewportwidth = document.getElementsByTagName(‘body’)[0].clientWidth,
       viewportheight = document.getElementsByTagName(‘body’)[0].clientHeight
}
document.write(‘<p>Your viewport width is ‘+viewportwidth+’x’+viewportheight+'</p>’);
//–>
</script>

This snippet will allow you to get the width and height of the display area in your views browser. This will give the designer the ability to create and use different displays based on the size of the user’s browser window.