Get Web ServerRelativeUrl by _spPageContextInfo or L_Menu_BaseUrl
http://blah.winsmarts.com/2013-2-_sppagecontextinfo_is_your_new_best_friend.aspx
http://sympmarc.com/2013/03/26/using-_sppagecontextinfo-to-determine-the-current-sharepoint-context-in-script/