You may also need the port number. If so, you can use this polyfill
if (!window.location.origin) {
window.location.origin = window.location.protocol + "//"
+ window.location.hostname
+ (window.location.port ? ':' + window.location.port : '');
}
This polyfill is already part of Modernizr.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…