[removed].href () and Window.open () in JavaScript

后端 未结 2 556
独厮守ぢ
独厮守ぢ 2021-01-04 19:37

What is the difference between window.location.href () and window.open() methods in JavaScript?

相关标签:
2条回答
  • 2021-01-04 20:17

    window.location is an Object and

    window.location.href is its property

    It tells you the current URL location of the browser

    document.write(location.href);// will give location URL location of browser.
    

    Setting the property will redirect the page.

    window.open() is a method that you can pass a URL to that you want to open in a new window

    E.g

    window.location.href = 'http://www.xyz.com'; //Will take you to xyz.

    window.open('http://www.xyz.com'); //This will open xyz in a new window.

    0 讨论(0)
  • 2021-01-04 20:23

    window.location.href changes the immediate window location.

    window.open() will open a new window.

    0 讨论(0)
提交回复
热议问题