2013-09-05 76 views
6

Sự khác nhau giữa các phương thức window.location.href()window.open() trong JavaScript là gì?Window.location.href() và Window.open() trong JavaScript

+0

có thể trùng lặp của [ Các phương thức Window.location.href và Window.open() trong JavaScript] (https://stackoverflow.com/questi tiện ích/7077770/window-location-href-and-window-open-methods-in-javascript) –

Trả lời

19

window.location là một Object

window.location.href được tài sản của mình

Nó cho bạn biết vị trí URL hiện tại của trình duyệt

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

Thiết bất động sản sẽ chuyển hướng t trang của anh ấy.

window.open() là một phương pháp mà bạn có thể vượt qua một URL để mà bạn muốn mở trong một cửa sổ mới

Ví dụ

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.

5

window.location.href thay đổi vị trí cửa sổ ngay lập tức.

window.open() sẽ mở một cửa sổ mới.

Các vấn đề liên quan