Creating opensocial gadgets
One answer
If your gadget is using an AjaxModule, we write the base tag into the html, so you can use:
var baseURI = document.baseURI;
if (!baseURI) {
var baseTags = document.getElementsByTagName('base');
baseURI = (baseTags && baseTags[0].href) || document.location.href;
}