Skip to content

Instantly share code, notes, and snippets.

@samuelcole
Created December 13, 2010 23:51
Show Gist options
  • Save samuelcole/739810 to your computer and use it in GitHub Desktop.
Save samuelcole/739810 to your computer and use it in GitHub Desktop.
A little function that accepts a url, and returns a url that matches the current protocol.
window.match_protocol = function(url) {
var RE_PROTO = /^\w+:\/\//;
if(RE_PROTO.test(url)) {
var protocol = window.location.protocol;
url = url.replace(RE_PROTO, protocol + "//");
}
return url;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment