I am trying to find how can I detect with JavaScript if I am in a HTTP or HTTPS environment.
I am calling an Ajax request so if I am in HTTPS and call HTTP Ajax then I get a 302 Moved Temporarily.
I was thinking of getting the current window.location.href
and do a string manipulation.
What is the best way of detecting HTTPS using JavaScript?
Looking at how google analytics add their script to the page:
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
Then document.location.protocol would seem safe for all browsers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With