W3Schools Popup Window JavaScript Tutorial

Sarah Jul 13, 2026

w3schools, a popular learning platform for web development, offers a wealth of resources and examples to help users understand JavaScript. One feature that can enhance the learning experience is the use of popup windows. Popups are used to display additional information, warnings, or interactive content without disturbing the user's flow through the main web page. Let's explore how to create popup windows using JavaScript based on w3schools examples.

JavaScript Window Events: Control Browser Behavior Like a Pro 🌍
JavaScript Window Events: Control Browser Behavior Like a Pro 🌍

JavaScript allows us to open a new browser window or tab with the help of the window.open() method. This method takes three parameters: the URL to open, the window name (if you want to open it in a new tab or window), and some optional features.

Modal Popup In JavaScript With Source Code
Modal Popup In JavaScript With Source Code

Creating a Simple Popup Window

In this section, we'll create a basic popup window that displays a new URL.

Very Simple Popup In Vanilla CSS & Javascript
Very Simple Popup In Vanilla CSS & Javascript

First, we'll need to link our HTML file to JavaScript. Include the <script> tag in the <head> section of your HTML file and call your JavaScript function within an <a> tag in the body of your HTML.

Opening a URL in a New Window

Javascript Window.print()
Javascript Window.print()

To open a new window with a specific URL, you can use the following code:

<a href="#" onclick="window.open('https://www.w3schools.com/', '_blank')">Open w3schools homepage</a>

Here, replace 'https://www.w3schools.com/' with the URL you want to open in the popup.

an image of a computer screen with headphones on it and another screenshot of the web page
an image of a computer screen with headphones on it and another screenshot of the web page

Naming the Popup Window

You can also give your popup window a name, which can be useful if you want to open multiple popup windows or target them with more specific JavaScript commands. Here's how you can do it:

<a href="#" onclick="window.open('https://www.w3schools.com/', 'mywindow')">Open w3schools homepage</a>

Popup In Pure CSS and HTML | Get Example With Source Code
Popup In Pure CSS and HTML | Get Example With Source Code

Each subsequent call to window.open() with the same name will open a new tab or window and not replace the existing one.

Popup Window Options

Css download button
Css download button
Javascript Fundamental
Javascript Fundamental
an image of a computer screen with some type of text and pictures on the screen
an image of a computer screen with some type of text and pictures on the screen
Create Image Accordion Slider With HTML CSS And JavaScript
Create Image Accordion Slider With HTML CSS And JavaScript
Responsive Animated Login and Signup Page with HTML CSS And JavaScript
Responsive Animated Login and Signup Page with HTML CSS And JavaScript
a laptop with the text 17 programming projects build fun projects for your website right away
a laptop with the text 17 programming projects build fun projects for your website right away
Windows Error message generator
Windows Error message generator
HTML Code For Popup Window on Page Load
HTML Code For Popup Window on Page Load
Toggle Fullscreen Mode in Javascript
Toggle Fullscreen Mode in Javascript
JavaScript Works in the Browser
JavaScript Works in the Browser
Css
Css
JavaScript Projects That Will Make You Better Fast 😳
JavaScript Projects That Will Make You Better Fast 😳
JavaScript Full Notes Every Beginner Must Save 💡
JavaScript Full Notes Every Beginner Must Save 💡
Dynamic Class Toggle in DOM
Dynamic Class Toggle in DOM
two screens showing different types of webpages and the same one with words on them
two screens showing different types of webpages and the same one with words on them
3D room - pure CSS
3D room - pure CSS
an image of a screen with text on it that says, simple like button animation
an image of a screen with text on it that says, simple like button animation
Monstro Galáctico
Monstro Galáctico
Top JavaScript Tricks Every Developer Should Know
Top JavaScript Tricks Every Developer Should Know
Page turning animation
Page turning animation

Besides the URL and window name, the window.open() method also has several optional parameters that allow you to control the size, position, and behavior of the popup window.

For example, you can specify the popup window's width and height like this:

<a href="#" onclick="window.open('https://www.w3schools.com/', 'mywindow', 'width=500,height=500')">Open w3schools homepage</a>

Resizable and Scrollbars

You can specify whether the popup window is resizable and whether it has scrollbars by adding the resizable and scrollbars parameters:

<a href="#" onclick="window.open('https://www.w3schools.com/', 'mywindow', 'width=500,height=500,resizable=no,scrollbars=yes')">Open w3schools homepage</a>

Other optional parameters include location, menubar, status, and toolbar, which enable or disable the respective browser features in the popup window.

Remember that not all popup features are supported in all browsers, and some features like resizing and moving the popup window might not be possible in all environments. The popup window's appearance and behavior can also be influenced by the user's browser settings.

In conclusion, w3schools provides a straightforward way to create popup windows using JavaScript. Opens new opportunities for creating interactive websites and web applications by leveraging this feature. Happy coding!