open ilnk target js
Open link target js
When you want to open a link in a new tab or window using JavaScript, you can use the window.open()
method with a second argument specifying the target.
Example:
window.open("http://example.com", "_blank");
The second argument "_blank" specifies that the link should be opened in a new window. Other possible values for the target parameter are:
- "_self": open the link in the same window/tab (this is the default).
- "_parent": open the link in the parent frame (if the current window is a frame).
- "_top": open the link in the topmost frame (if the current window is a frame).
- a custom name: open the link in a named window, which can be reused by later links with the same name.
Example with custom name:
window.open("http://example.com", "myWindow");
You can also set additional options for the new window, such as its size, position, and features (like whether or not it has a status bar). These options are specified as a comma-separated string in the third argument of window.open()
.
Example with options:
window.open("http://example.com", "_blank", "width=500,height=500,status=yes");
Using window.open()
can be useful when you want to provide a quick way for users to open a link in a new window, without having to right-click and select "Open in new window/tab" from the context menu.