The Little JavaScript Gifts from SharePoint

Ever needed to quickly figure out what web application you are in using JavaScript? Or get the site collection URL?

SharePoint has a fantastic somewhat little know JavaScript object declared in the MasterPage.

_spPageContextInfo

This object contains a ton of useful contextual information that can be accessed simply by referencing it:

<script type="text/javascript">
var loginName = _spPageContextInfo.userLoginName
alert(loginName)
</script>

There is a fantastic listing of all the different properties here: http://blah.winsmarts.com/2013-2-_sppagecontextinfo_is_your_new_best_friend.aspx