Try to use the get_Current() functionYou can do it like this:
<script>
function GetSiteUrl()
{
var ctx = new SP.ClientContext.get_current();
var site = ctx.get_site();
var siteUrl = ctx.load(site);
ctx.executeQueryAsync(function(s, a){alert(site.get_url())});
}
</script>
<a href='javascript:GetSiteUrl();'>Get site URL</a>
To load only the URL from the site to minimize data traffic you can also call:
ctx.load(site, 'Url');
For more see reference: http://msdn.microsoft.com/en-us/library/ee538253.aspx