tags:

views:

31

answers:

2
+2  Q: 

js detect https

Hi,

i am trying to find how can i "detect" width JavaScript if i am ih http or https environment

I am calling ajax request so if i am in https and call http ajax i get 302 Moved Temporarily

I was thinking of get the current window.location.href and do a strinh manipulation

Any suggestion is welcome.

+4  A: 

You can use the non-standard

window.location.protocol 

In Firefox: MDC documentation

In IE, it seems to be

 document.location.protocol

MSDN documentation

I can't find reliable info on how this behaves on other browsers, but I expect they adhere to the quasi-standard of document.location.protocol.

Maybe the jQuery url plugin sorts this out without having to deal with cross-browser differences - I've never used it myself, but it looks promising:

jQuery.url.attr("protocol");
Pekka
+1: that is more generic way for it :)
Sarfraz
A: 

location.protocol works on both browsers

Ryan Fernandes
There are more than two browsers :)
Pekka
ouch! thanks for snapping me back to reality :)
Ryan Fernandes