-
-
Save otolab/f8c0cfeeecd723e20a5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* to-absolute-url.js | |
* | |
* @version 1.0.1 | |
* @author think49 | |
* @url https://gist.github.com/think49/1e8944a19a36dd57c829 | |
* @license http://www.opensource.org/licenses/mit-license.php (The MIT License) | |
*/ | |
'use strict'; | |
var toAbsoluteUrl = (function (currentDirectory, anchorElement) { | |
var toAbsoluteUrl; | |
function toAbsoluteUrlByHref (url) { | |
anchorElement.href = url; | |
return anchorElement.href; | |
} | |
function toAbsoluteUrlByCloneHref (url) { | |
anchorElement.href = url; | |
return anchorElement.cloneNode(false).href; // for IE6, IE7 | |
} | |
if (toAbsoluteUrlByHref('t') === currentDirectory + 't') { | |
toAbsoluteUrl = toAbsoluteUrlByHref; | |
} else if (toAbsoluteUrlByCloneHref('t') === currentDirectory + 't') { | |
toAbsoluteUrl = toAbsoluteUrlByCloneHref; | |
} else { | |
throw new Error; | |
} | |
return toAbsoluteUrl; | |
})(location.protocol + '//' + location.host + location.pathname.replace(/[^\x2f]+$/, ''), document.createElement('a')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment