Skip to content
the poor coder

open ilnk target js

Poor Man
Published
Reading time
1 min read
On this page

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:#

Text
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:#

Text
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:#

Text
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.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC