Skip to content

Instantly share code, notes, and snippets.

@a-ignatov-parc
Last active November 10, 2015 10:09
Show Gist options
  • Save a-ignatov-parc/df79dded2b7fcec92017 to your computer and use it in GitHub Desktop.
Save a-ignatov-parc/df79dded2b7fcec92017 to your computer and use it in GitHub Desktop.
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