windows JavaScript 中的 Window.location.href() 和 Window.open()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18634383/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Window.location.href () and Window.open () in JavaScript
提问by khalid jarrah
What is the difference between window.location.href ()
and window.open()
methods in JavaScript
?
window.location.href ()
和 中的window.open()
方法有JavaScript
什么区别?
回答by Dipak Ingole
window.location
is an Objectand
window.location
是一个对象并且
window.location.href
is its property
window.location.href
是它的财产
It tells you the current URL locationof the browser
它告诉你浏览器的当前 URL 位置
document.write(location.href);// will give location URL location of browser.
Setting the property will redirectthe page.
设置该属性将重定向页面。
window.open()
is a methodthat you can pass a URL to that you want to open in a new window
window.open()
是一种方法,您可以将 URL 传递给要在新窗口中打开的 URL
E.g
例如
window.location.href = 'http://www.xyz.com'; //Will take you to xyz.
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.
window.open('http://www.xyz.com'); //This will open xyz in a new window.
回答by Lloyd
window.location.href
changes the immediate window location.
window.location.href
更改直接窗口位置。
window.open()
will open a new window.
window.open()
将打开一个新的窗口。