Home > Web Front-end > JS Tutorial > body text

What is the difference between `window.location.href` and `window.open()` in JavaScript?

Patricia Arquette
Release: 2024-11-05 09:41:02
Original
192 people have browsed it

What is the difference between `window.location.href` and `window.open()` in JavaScript?

Differences Between window.location.href and window.open() Methods in JavaScript

The distinction between window.location.href and window.open() lies in their nature and functionality.

window.location.href

  • Is not a method but a property.
  • Retrieves the current URL location of the browser.
  • Modifying its value redirects the current page.

Example:

<code class="javascript">window.location.href = "http://www.example.com"; // Redirects to example.com</code>
Copy after login

window.open()

  • Is a method that takes a URL argument.
  • Creates a new browser window or tab and navigates it to the specified URL.

Example:

<code class="javascript">window.open("http://www.google.com"); // Opens Google in a new window</code>
Copy after login

Additional Features

  • window.open() can take additional parameters to customize the new window, such as its size, location, and features (e.g., menubar, toolbar).
  • For more information on window.open() parameters, refer to the window.open tutorial.

The above is the detailed content of What is the difference between `window.location.href` and `window.open()` in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!