Created
December 13, 2012 06:50
-
-
Save khakimov/4274609 to your computer and use it in GitHub Desktop.
http to https
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
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