How can we parse the request header in Java scipt to find out the protocol of the request, whether it is http or https?

Thanks in advance
Nivedita

Recommended Answers

All 3 Replies

To my knowledge, you can't use JavaScript for this. JavaScript has a limited set of core operators, statements, and objects.

In this case, I would think the Document object would be the relevant one. I don't see any method or property of the browser DOM that returns header information (besides the "mimeType" property).

If I'm wrong, someone please correct me. I think you'll need a server-side language for this.

Just A Thought Here, Couldn't You Get The Referer With Javascript (like document.referer), and doesn't it return an entire URL? If this is so, couldn't you split the string (or use substr) and grap the protocol, and check for http: or https: and act accordingly?

That's what I get for reading posts too quickly. For some reason I had in mind the OP was asking if JavaScript could tell if the page was sent in response to a POST or GET header.

If you simply want to check the URL, then yes, your technique should work.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.