Skip to content

Instantly share code, notes, and snippets.

@duzun
Created December 27, 2014 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duzun/2df4637780c8a599bd96 to your computer and use it in GitHub Desktop.
Save duzun/2df4637780c8a599bd96 to your computer and use it in GitHub Desktop.
/**
* A script for transitioning to HTTPS for clients that support it.
*
* This script will make a request to https:yourdomain.com/ping?_clb_=?
* from the loaded http: document.
* If the request is successful, it will convert all the internal links
* to https:
*/
jQuery(function ($) {
if(location.protocol === 'http:') {
// Check for HTTPS support
setTimeout(function () {
var host = location.host
, proto = 'https:'
, url = proto + '//' + host + '/ping?_clb_=?'
;
$.getJSON(url).done(function (x) {
// If HTTPS is supported, switch all internal links to https:
if(x && (x.ok || x.ts)) {
$('a[href]')
.each(function (i,a) {
if(a.host == host) {
a.protocol = proto;
}
})
;
}
})
}, 1e2);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment