Open a new tab javascript
A simple one!
To open a new tab in JavaScript, you can use the following code:
window.open('https://www.example.com', '_blank');
Here's a breakdown of the code:
window.open()
is the method that opens a new tab.- The first argument is the URL you want to open in the new tab. In this case, it's
https://www.example.com
. - The second argument is the target attribute, which specifies where the new tab should be opened.
_blank
tells the browser to open the new tab in a new window or tab.
You can also add additional options to the window.open()
method, such as:
window.open('https://www.example.com', '_blank', 'width=500,height=300');
- This would open a new tab with a width of 500 pixels and a height of 300 pixels.window.open('https://www.example.com', '_blank', 'noopener');
- This would open a new tab with thenoopener
attribute, which prevents the new tab from accessing the parent window.
Note that the window.open()
method returns a reference to the new window or tab, which you can use to interact with it programmatically.