javascript - JavaScript 中的 window.location.href 和 window.open() 方法

标签 javascript location window href window-object

JavaScript中的window.location.hrefwindow.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/

相关文章:

javascript - 提交表单失败时运行函数

android - Google (Play) sleep 模式下的位置服务更新间隔变化 (Android)

内存位置的 C++ 范围错误?

我可以阻止我的程序的用户调整控制台窗口的大小吗? (在 C 中)

python - 将 openCV 窗口置于前面并关注焦点 macOS

javascript - 检查多个字符串以匹配多个正则表达式(均为数组)

javascript - 在 Codeigniter 模式中将变量从 Javascript 传递到 href

javascript - 如何从父对象获取对象的属性值

testing - 为 Grails 单元测试使用不同的结构

c# - 识别应用程序的状态