Change UTC date time to local date time in javascript/jquery

// php code to get current UTC date time
$utcDateTime = date('Y-m-d h:m:s');

<script src=""></script>

<script src=""></script>
$(document).ready(function() {
var utcDateTime = '<?php echo $utcDateTime; ?>';

var dateTime = moment.utc(utcDateTime).toDate(); var localDateTime = moment(dateTime).format('YYYY-MM-DD HH:mm:ss');

UTC : <div id="utc_date_time"></div></br>
Local: <div id="local_date_time"></div> ...  Read More

Share This:

Tweets count api in javascript/jquery

<script src=""></script>

function getTweetsCount(username, callback) { $.getJSON("*%20from%20html%20where%20url%3D'" + username + "'%20and%20xpath%3D'%2F%2Finput%5B%40id%3D%22init-data%22%5D'&format=json&", function (data) { callback(data.query.results.input.value.match(/statuses_count":(\d+)/)[1]); }); }

getTweetsCount('coding_4_devs', function (count) { $('#tweet-count').html("<h2>Tweet Count: "+count+"</h2>") });


<div id="tweet-count"> <h2>Loading...</h2> </div>

Share This:

Twitter follower count api in javascript/jquery

<script src=""></script>

function getTwitterFollowerCount(username, callback) { $.getJSON("*%20from%20html%20where%20url%3D'" + username + "'%20and%20xpath%3D'%2F%2Finput%5B%40id%3D%22init-data%22%5D'&format=json&", function (data) { callback(data.query.results.input.value.match(/followers_count":(\d+)/)[1]); }); }

getTwitterFollowerCount('coding_4_devs', function (count) { $('#follower-count').html("<h2>Twitter Followers Count: "+count+"</h2>") });


<div id="follower-count"> <h2>Loading...</h2> </div>

Share This:

Facebook page likes count api in javascript/jquery

You can get your Facebook page likes count in JavaScript/JQuery. You will require to pass your Facebook page id or Facebook page name and (App ID|App Secret).

You can get Facebook App ID and Facebook Secret Id from your developers account.

Visit and select your page in 'My Apps' and now you can get App ID and Secret ID.


Share This:

Get browser name in javascript

<script> var nAgt = navigator.userAgent; var browserName = navigator.appName; var nameOffset,verOffset,ix; if ((verOffset=nAgt.indexOf("OPR/"))!=-1) { browserName = "Opera"; } else if ((verOffset=nAgt.indexOf("Opera"))!=-1) { browserName = "Opera"; } else if ((verOffset=nAgt.indexOf("MSIE"))!=-1) { browserName = "Microsoft Internet Explorer"; } else if ((verOffset=nAgt.indexOf("Chrome"))!=-1) { browserName = "Chrome"; } else if ((verOffset=nAgt.indexOf("Safari"))!=-1) { browserName = "Safari"; } else if ((verOffset=nAgt.indexOf("Firefox"))!=-1) { browserName = "Firefox"; } else if ( (nameOffset=nAgt.lastIndexOf(' ')+1) < (verOffset=nAgt.lastIndexOf('/')) ) { browserName = nAgt.substring(nameOffset,verOffset); if (browserName.toLowerCase()==browserName.toUpperCase()) { browserName = navigator.appName; } } document.write('Browser name = '+browserName) </script>

Share This:

Redirect after a time in Javascript

<html> <head> <script type="text/javascript"> function Redirect() { window.location=""; }

document.write("You will be redirected to main page in 10 sec.");
setTimeout('Redirect()', 10000);


Share This:

Object oriented programming in jquery/javascript

With the basics out of the way, we'll now focus on object-oriented JavaScript (OOJS) . This article presents a basic view of object-oriented programming with an example.


Share This:

Check background or foreground status of web app

I'd like to check weather my web application is running in background or foreground, You can check it very easily in JavaScript. hasFocus() is the function which tells that your window is active or not.

Here in below example I have create checkForeGroundBackGround() function and inside the body of it we check the window status.

We call back checkForeGroundBackGround() function periodically to check the status.

window.document.hasFocus() returns the web app status true if app is in foreground and false if app is in background. ...  Read More

Share This:

Check internet connection on webpage

We can check the internet connection so that if there is no internet in between we can let user know that no internet connection.
Here in below example we call the checkInternetConnection() function periodically. So that we can detect the internet connection on web page.

Here we are checking internet connection by navigator.onLine. It returns true if there is internet connection and returns false if there is no internet connection. 

Share This:

Calling a function after time interval in javascript

If you wanted to do some stuff after time interval so here is the solution for you.

Here setInterval() method will call test() method after each 2 seconds.

Share This: