Window.location.href () and Window.open () in JavaScript

Window.location.href () and Window.open () in JavaScript

本文关键字:Window in JavaScript open and location href      更新时间:2023-09-26

JavaScriptwindow.location.href ()方法和window.open()方法有什么区别?

window.location是一个对象

window.location.href是它的属性

它告诉您浏览器的当前URL位置

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

设置该属性将重定向页面。

window.open()是一种方法,您可以将要在新窗口中打开的 URL 传递到

该方法

例如

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.location.href更改即时窗口位置。

window.open()将打开一个新窗口。