If you want to know what the difference is between window.location.href and window.open and which one is best to use , then in this article, I shall explain the difference.

What is window.location.href ?

window.location.href is not a method or function. It's a property that allow us to get the url of current browser.

Get current browser URL
     function myFunction1(){
        document.write(window.location.href) ;

}
  
Try it Yourself »

window.location.href opens a url in the same window in which the js code is called.

Example of window.location.href property
    function myFunction2(){
     window.location.href="https://www.example.com";
      }
  
Try it Yourself »

What is window.open?

window.open is a method that will open the url in a new browser.

Example of window.open() method
   function myFunction1(){
       window.open("https://www.example.com");
}
  
Try it Yourself »