How to Open URL in New Tab using JavaScript? Last Updated : 28 Jun, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report To open a URL in a new tab using JavaScript, we can use the window.open() method. The window.open() method is used to open a new browser window or tab. It can also be used to load a specific URL in a new tab. Syntaxwindow.open(URL, '_blank');window.open(): Opens a new tab or window.First Parameter: The URL you want to open, e.g., "https://www.example.com".Second Parameter ("_blank"): Tells the browser to open the URL in a new tab.Return Value: The method returns a reference to the new tab/window or null if it fails. HTML <html> <head></head> <body> <p> Click the button to open <b> geeksforgeeks.org </b> in new tab </p> <button onclick="NewTab()"> Open Geeksforgeeks </button> <script> function NewTab() { window.open( "https://www.geeksforgeeks.org", "_blank"); } </script> </body> </html> Output:How to Open URL in New Tab using JavaScript?In this exampleA button labeled "Open GeeksforGeeks" is provided for the user to click.When the button is clicked, it triggers the NewTab() function.The window.open() method in NewTab() opens the URL "https://www.geeksforgeeks.org" in a new tab ("_blank").Important Notes:The return value of window.open() is a reference to the newly created window or tab. It returns null if it fails to open the new tab.Avoid adding a third parameter to the window.open() method because it could result in a new window instead of a tab.Handling User InteractionsMost modern browsers block pop-ups, including the window.open() method, when it's not triggered by a direct user action (e.g., a click). To avoid this, ensure that the window.open() method is called inside an event handler like onclick. HTML <html> <head> <style> body { display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; font-family: Arial, sans-serif; } button { padding: 10px 20px; font-size: 16px; cursor: pointer; } </style> </head> <body> <p>Click the button to open <b>GeeksforGeeks</b> in a new tab:</p> <button onclick="NewTab()">Open GeeksforGeeks</button> <script> function NewTab() { window.open("https://www.geeksforgeeks.org", "_blank"); } </script> </body> </html> OutputHow to Open URL in New Tab using JavaScript?In this exampleWhen clicked, it runs the NewTab() function.window.open("https://www.geeksforgeeks.org", "_blank"); opens the GeeksforGeeks website in a new tab.Applications of Opening URLs in New TabsHere are the applications of opening URLs in new tabs:External Links: When linking to external websites, it’s best to open them in a new tab to keep users on your site.Forms and Documentation: If you are providing a form or documentation with links to other pages, opening them in new tabs is helpful.Pop-up Windows: Sometimes you might want to create a pop-up window that behaves like a new tab for displaying additional content.Difference Between window.open() vs <a> tagHere is a detailed difference between window.open() vs <a> tag based on their features.window.open()<a> TagIt is used in JavaScript to open a URL programmatically.It is Used in HTML to create a link that can be clicked.More control (e.g., can open in new tab, window, or popup).Less control, opens in the same window or new tab."_blank" opens in a new tab, but requires JavaScript.target="_blank" opens in a new tab, simple HTML.Requires JavaScript enabled.Works without JavaScript.Highly customizable, can control window size, position, etc.Limited customization (just target behavior).May be blocked by pop-up blockers if overused.Safe and standard for linking.Needs extra handling for accessibility (keyboard, focus, etc.).Simple and accessible by default. Comment More infoAdvertise with us H harshcooldude700 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Questions Similar Reads Non-linear Components In electrical circuits, Non-linear Components are electronic devices that need an external power source to operate actively. Non-Linear Components are those that are changed with respect to the voltage and current. Elements that do not follow ohm's law are called Non-linear Components. Non-linear Co 11 min read JavaScript Tutorial JavaScript is a programming language used to create dynamic content for websites. It is a lightweight, cross-platform, and single-threaded programming language. It's an interpreted language that executes code line by line, providing more flexibility.JavaScript on Client Side: On the client side, Jav 11 min read Web Development Web development is the process of creating, building, and maintaining websites and web applications. It involves everything from web design to programming and database management. Web development is generally divided into three core areas: Frontend Development, Backend Development, and Full Stack De 5 min read Spring Boot Tutorial Spring Boot is a Java framework that makes it easier to create and run Java applications. It simplifies the configuration and setup process, allowing developers to focus more on writing code for their applications. This Spring Boot Tutorial is a comprehensive guide that covers both basic and advance 10 min read React Interview Questions and Answers React is an efficient, flexible, and open-source JavaScript library that allows developers to create simple, fast, and scalable web applications. Jordan Walke, a software engineer who was working for Facebook, created React. Developers with a JavaScript background can easily develop web applications 15+ min read React Tutorial React is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version 7 min read JavaScript Interview Questions and Answers JavaScript is the most used programming language for developing websites, web servers, mobile applications, and many other platforms. In Both Front-end and Back-end Interviews, JavaScript was asked, and its difficulty depends upon the on your profile and company. Here, we compiled 70+ JS Interview q 15+ min read Class Diagram | Unified Modeling Language (UML) A UML class diagram is a visual tool that represents the structure of a system by showing its classes, attributes, methods, and the relationships between them. It helps everyone involved in a projectâlike developers and designersâunderstand how the system is organized and how its components interact 12 min read Backpropagation in Neural Network Back Propagation is also known as "Backward Propagation of Errors" is a method used to train neural network . Its goal is to reduce the difference between the modelâs predicted output and the actual output by adjusting the weights and biases in the network.It works iteratively to adjust weights and 9 min read 3-Phase Inverter An inverter is a fundamental electrical device designed primarily for the conversion of direct current into alternating current . This versatile device , also known as a variable frequency drive , plays a vital role in a wide range of applications , including variable frequency drives and high power 13 min read Like