JavaScript window.location.protocol Property

You are Here:

JavaScript window.location.protocol Property

The window.location.protocol property returns the web protocol used by the current page (http: or https:).

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <script> document.write("Page protocol: "+window.location.protocol); </script> </body> </html>

Syntax

window.location.protocol

Return Value

ValueExplanation
StringReturns a string representing the web protocol used by the current page (http: or https:).

More Examples

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <script> var txt = ""; txt += "<p>Page location: "+window.location.href+"</p>"; txt += "<p>Page hostname: "+window.location.hostname+"</p>"; txt += "<p>Page path: "+window.location.pathname+"</p>"; txt += "<p>Page protocol: "+window.location.protocol+"</p>"; txt += "<p>Port number: "+window.location.port+"</p>"; document.write(txt); </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author