Javascript open new tab with url
A simple one!
To open a new tab with a URL using JavaScript, you can use the window.open()
method. Here's the basic syntax:
window.open(url, '_blank');
Where:
url
is the URL you want to open in the new tab._blank
is the target attribute that specifies the new tab.
Here's an example:
window.open('https://www.example.com', '_blank');
This will open a new tab with the URL https://www.example.com
.
You can also add additional options to the window.open()
method, such as:
window.open(url, '_blank', 'width=500,height=600');
- sets the width and height of the new tab.window.open(url, '_blank', 'toolbar=no,menubar=no');
- hides the toolbar and menubar in the new tab.
Note that the window.open()
method returns a reference to the new window, which you can use to interact with the new tab.
Alternatively, you can use the location.href
property to open a new tab:
location.href = 'https://www.example.com';
This will open a new tab with the specified URL, but it will not create a new window object, so you won't be able to interact with the new tab programmatically.
I hope that helps!