Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* 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