switch(window.location.protocol){ case "https:": return "https"; break; default: return "http"; break; }