Home >Web Front-end >JS Tutorial >How to Open the Current URL in a New Window with a Specific Size Using JavaScript?
Open URL in New Window with JavaScript
When creating a "share button" to share the current page, it's common to want to open the current URL in a new window. While retrieving the current URL is straightforward, specifying the new window's size can present challenges.
To resolve this issue, consider utilizing the window.open() function, which provides the ability to customize the new window's properties. The following code snippet demonstrates this approach:
<code class="html"><a onclick="window.open(document.URL, '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');"> Share Page </a></code>
In this code, the onclick event listens for a user's click and executes the window.open() function. The first argument specifies the URL to be opened, and '_blank' indicates that the URL should open in a new window. The subsequent parameters control the new window's properties, including its height, width, and whether it displays location, scrollbars, and status information.
This solution effectively allows you to create a link that opens the current URL in a new window with a specified size of 570 pixels in height and 520 pixels in width.
The above is the detailed content of How to Open the Current URL in a New Window with a Specific Size Using JavaScript?. For more information, please follow other related articles on the PHP Chinese website!