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 tutorial
关于javascript - JavaScript 中的 window.location.href 和 window.open() 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7077770/