Skip to content

Instantly share code, notes, and snippets.

@danieleremin
Last active December 6, 2020 00:26
Show Gist options
  • Save danieleremin/c5fbe14856e68fc9c8eb8d5d8db94b8a to your computer and use it in GitHub Desktop.
Save danieleremin/c5fbe14856e68fc9c8eb8d5d8db94b8a to your computer and use it in GitHub Desktop.
How to open a new window in front of the current one using JavaScript. Values can be changed for desirable result.
function NewWindow() {
window.open('page.html','about:blank','resizable=yes,scrollbars=yes,status=0,width=600,height=620');
}
// Call the function when a button is clicked.
// NOTICE: This will not work on mobile devices. On mobile devices this would function the same way target _blank on <a> HTML tag would. (Opens in new tab)
@danieleremin
Copy link
Author

danieleremin commented Dec 6, 2020

If you do not want an external javascript file or <script> tag you can just put the line of code directly into the HTML button (e.g. <button onclick="window.open('page.html','about:blank','resizable=yes,scrollbars=yes,status=0,width=600,height=620');")>Open</button> ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment