Skip to content

Instantly share code, notes, and snippets.

@khakimov
Created December 13, 2012 06:50
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 khakimov/4274609 to your computer and use it in GitHub Desktop.
Save khakimov/4274609 to your computer and use it in GitHub Desktop.
http to https
if (document.location.protocol === 'https:') {
// http to https for <link>
var links = document.getElementsByTagName('link');
for(i = 0; i < links.length; i++)
{
if(links[i].href.indexOf('http:') > -1) {
link = links[i].href.replace('http:', 'https:');
links[i].href = link;
}
}
// http to https for <script>
var scripts = document.getElementsByTagName('script');
for(i = 0; i < scripts.length; i++)
{
if(scripts[i].src.indexOf('http:') > -1) {
script = scripts[i].src.replace('http:', 'https:');
scripts[i].src = script;
}
}
// http to https for images
var images = document.getElementsByTagName('img');
for(i = 0; i < images.length; i++)
{
if(images[i].src.indexOf('http:') > -1) {
img = images[i].src.replace('http:', 'https:');
images[i].src = img;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment