Home > Article > Web Front-end > How Can I Open URLs in New Windows with JavaScript?
Opening URLs in New Windows with JavaScript
When creating share buttons, it's often desirable to open shared links in new windows. JavaScript provides utilities for achieving this, but getting the syntax right can be challenging.
Solution Using window.open()
To create a link that opens the current page URL in a new window with specific dimensions, utilize the window.open() method:
<a onclick="window.open(document.URL, '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');"> Share Page </a>
Explanation
The optional parameters define window attributes:
The above is the detailed content of How Can I Open URLs in New Windows with JavaScript?. For more information, please follow other related articles on the PHP Chinese website!