Last active
November 10, 2015 10:09
-
-
Save a-ignatov-parc/df79dded2b7fcec92017 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| function getUrlOrigin(url) { | |
| let link = document.createElement('a'); | |
| link.href = url; | |
| if (link.origin) { | |
| return link.origin; | |
| } | |
| // IE < Edge – наркоманы... не могут получить значение `origin`, не могут правильно | |
| // получить значение свойства `port` и под конец парсит `pathname` у ссылки иначе | |
| // чем `window.location`. | |
| return link.href.substring(0, link.href.lastIndexOf(link.pathname.replace(/^\/?/, "/"))); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment