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

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

<script src="http://momentjs.com/downloads/moment.js"></script>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<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_date_time').html(utcDateTime);
$('#local_date_time').html(localDateTime);
});
</script>
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="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>

function getTweetsCount(username, callback) { $.getJSON("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D'http%3A%2F%2Ftwitter.com%2F" + username + "'%20and%20xpath%3D'%2F%2Finput%5B%40id%3D%22init-data%22%5D'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys", 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>") });

</script>

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

Share This:


Twitter follower count api in javascript/jquery

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script>

function getTwitterFollowerCount(username, callback) { $.getJSON("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D'http%3A%2F%2Ftwitter.com%2F" + username + "'%20and%20xpath%3D'%2F%2Finput%5B%40id%3D%22init-data%22%5D'&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys", 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>") });

</script>

<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 https://developers.facebook.com 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:


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: