JavaScript to detect if the parent frame is of the same origin?-Collection of common programming errors

I use this method to tell if an iframe contains local content,

but you can pass it window.top from the iframe just as well

function islocal(win){
var H=location.href,
    local= H.substring(0, H.indexOf(location.pathname));
    try{
        win=win.document;
        return win && win.URL && win.URL.indexOf(local)== 0;
    }
    catch(er){
        return false
    }
}

//test case alert(islocal(window.top))