在JavaScript中,window.location.href
和window.open()
方法之间有什么区别?
window.location.href`不是一个方法,它是一个属性,将告诉你浏览器的当前URL位置。改变该属性的值将重定向该页面。
window.open()
是一个方法,你可以传递一个你想在新窗口打开的URL。比如说。
window.location.href 示例:
window.location.href = 'http://www.google.com'; //Will take you to Google.
window.open() 示例:
window.open('http://www.google.com'); //This will open Google in a new window.
window.open()
可以传递额外的参数。参见。window.open教程。
window.open()
将打开一个新窗口,而window.location.href
将在当前窗口中打开新的URL。