I am trying to test if a webpage is HTTP and then if so, I want it to go to the HTTPS version of the site. However, it is not working. For some reason, no error message is thrown, but it doesn't execute. The javascript is on domain1.com and the webpage is on domain2.com
domain1.com/sec/sec.js:
function sec(){
var loc = window.location.href;
loc.replace("http", "https");
for(window.location.href; window.location.href != loc;){
window.location = loc;
}
}
domain2.com/index.html
<html>
<head>
<title></title>
<script src = "domain1.com/sec/sec.js"></script>
<script>sec();</script>
</head>
</html>
Anyone have any working code snippets? Thank you!
I think this will help you.
function Check(){
return location.protocol === 'https:'
}
if ( !Check()){
var _location = location.toString();
var _newLink = _location.replace('http:', 'https:');
location = _newLink ;
}