Skip to content

Instantly share code, notes, and snippets.

@catichenor
Created February 28, 2017 00:21
Show Gist options
  • Select an option

  • Save catichenor/627ff6450b031114abe13201b7062d6c to your computer and use it in GitHub Desktop.

Select an option

Save catichenor/627ff6450b031114abe13201b7062d6c to your computer and use it in GitHub Desktop.
Change relative URL to absolute URL in Javascript
// Adapted from https://muaz-khan.blogspot.com/2012/02/absolute-or-relative-url-issues-and.html
function qualifyURL(url) {
var a = document.createElement('a');
a.href = url; // set string url
url = a.href; // get qualified/absolute url
a.href = null; // no server request
return url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment