java script get hostname code example Example: javascript get current url var currentUrl = window.location.href;