As has already been mentioned there is the as yet not fully supported window.location.origin
but instead of either using it or creating a new variable to use, I prefer to check for it and if it isn't set to set it.
For example;
if (!window.location.origin) {
window.location.origin = window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '');
}
I actually wrote about this a few months back A fix for window.location.originA fix for window.location.origin