Saturday, November 18, 2017

JavaScript Function to get the website URL Value


This JavaScript function will return the URL name along with the protocol ('http' or 'https') value.

function GetHost() {

        if (typeof location.protocol == 'undefined') {

            alert('location.protocol is undefined');

        }

        if (typeof location.host == 'undefined') {

            alert('location.protocol is undefined');

        }

        let host = location.protocol + '//' + location.host + '/';

        return host;

    }

No comments:

Post a Comment

All Blogs so far ...