Javascript - Open a given URL in a new window/tab by clicking a button

Use the following code to open a link in a new window rather than a new tab, as you can see, I've used a button, but the same onclick="..." can be used on anything to make it open the specified URL in a new window:

<input type="button" value="button name" onclick="window.open('http://www.website.com/page')" />

You can also add variables to it to stop it from showing specific browser traits for example, the menu bar. Parameters can be assigned as follows:

onclick="window.open(this.href,'popUpWindow','height=400,width=600,left=10,top=10,,scrollbars=yes,menubar=no'); return false;"

Published at

Tags: JavaScript

Luke Alderton

Comments

Post a comment
Sit tight...
We're adding your comment.
Thank you.
Your comment has been added.
There's been a problem.
Please try again later.
Share with
Tags
Latest Comments
By Alexander Gontar on Xamarin Forms - Working with threads
13 Mar 2020, 07:10 AM
By Arthur Richardson on Disabling XAML Hot Reload
12 Mar 2020, 17:52 PM
By George on Xamarin Forms - Working with threads
10 Mar 2020, 05:04 AM
By Darío on Xamarin forms - Stop/Cancel back button event
1 Mar 2020, 03:00 AM
By Benjamin Roberts on Simple fix for 'Cannot bind source type Umbraco.Web.Models.RenderModel to model type xx'
17 Feb 2020, 19:45 PM
By Chris Boot on Xamarin Forms multiple instances of same app open
26 Jan 2020, 17:10 PM
By Hannah on Xamarin forms - Stop/Cancel back button event
14 Jan 2020, 02:28 AM
By SK on Xamarin forms - Stop/Cancel back button event
14 Dec 2019, 02:06 AM
Categories
App Development
Event
Game Development
Mapping
Modelling
Programming
Review
Robotics
Tutorial
Web Development