Open URL in new window with JavaScript
Use window.open()
:
<a onclick="window.open(document.URL, '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');">
Share Page
</a>
This will create a link titled Share Page
which opens the current url in a new window with a height of 570 and width of 520.
Open a URL in a new tab (and not a new window)
Nothing an author can do can choose to open in a new tab instead of a new window; it is a user preference. (Note that the default user preference in most browsers is for new tabs, so a trivial test on a browser where that preference hasn't been changed will not demonstrate this.)
CSS3 proposed target-new, but the specification was abandoned.
The reverse is not true; by specifying certain window features for the window in the third argument of window.open()
, you can trigger a new window when the preference is for tabs.
How to open a link in a new window?
This is how to open a link in a new window.
<a href="myLink"
target="popup"
onclick="window.open('myLink','popup','width=600,height=600'); return false;">
Open Link in Popup
</a>
Always remember the sometimes that user configures their browsers to block all new tabs and windows (at least this is what I do), to avoid annoying advertisements and click baits links.
JavaScript open in a new window, not tab
Specify window "features" to the open
call:
window.open(url, windowName, "height=200,width=200");
When you specify a width/height, it will open it in a new window instead of a tab.
See https://developer.mozilla.org/en-US/docs/Web/API/Window.open#Position_and_size_features for all the possible features.
Related Topics
How to Add New Array Elements at the Beginning of an Array in JavaScript
How to Get a JavaScript Object's Class
Are There Constants in JavaScript
Detecting Arrow Key Presses in JavaScript
How to Get the Size of a JavaScript Object
How to Check If Dst (Daylight Saving Time) Is in Effect, and If So, the Offset
How to Get Character Array from a String
Node.Js Plans to Support Import/Export Es6 (Ecmascript 2015) Modules
What Is the Purpose of a Plus Symbol Before a Variable
Convert Base64 String to Arraybuffer
How to Make a Promise from Settimeout
How to Submit a Form Using JavaScript
Object Property Name as Number
How to Concatenate a String with a Variable
Please Explain the Use of JavaScript Closures in Loops
How to Resize Images Proportionally/Keeping the Aspect Ratio