Home > Article > Web Front-end > How to Open a URL in a New Window with JavaScript: A Comprehensive Guide
Open URL in New Window with JavaScript: A Comprehensive Solution
Creating a share button that launches the current page URL in a new window requires precise JavaScript syntax. To achieve this, we turn to the versatile window.open() method.
The following code snippet offers a comprehensive solution, incorporating both the desired URL substitution and window size specifications:
<code class="html"><a onclick="window.open(document.URL, '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');"> Share Page </a></code>
Let's break down the code:
When the user clicks on the "Share Page" link, this JavaScript code executes, opening the current URL in a new window with the specified dimensions and other functionalities. By combining window.open() with tailored window attributes, you can seamlessly open specific URLs in separate windows, catering to your precise requirements.
The above is the detailed content of How to Open a URL in a New Window with JavaScript: A Comprehensive Guide. For more information, please follow other related articles on the PHP Chinese website!