Created
December 27, 2014 19:17
-
-
Save duzun/2df4637780c8a599bd96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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