JS opens new tab (window.open application)

How to open a new tab in JS

By setting target="_blank" in the a tag , you can achieve the effect of opening a new tag. But sometimes we need to open a new tab through Javascript, so how to achieve it?
Methods as below:

window.open(“http://www.wlzhys.com“);

or:

window.open("http://www.wlzhys.com", "_blank"); //Pay attention to the second parameter

Precautions:

  1. In IE, if the domain name to be opened and the current domain name do not belong to the same main domain name, it will be opened in a new window (the same is true for labels).
  2. In Chrome, if the window.open() function is not called by mouse and keyboard events, but is called directly by the page or through a timer (including timers triggered by mouse and keyboard), a new window will be opened instead of a tab.
  3. In a new window or new tab, the _parent and _top parameters of window.open() are invalid (only valid when in a frame).
  4. The framename parameter can be set to the name value of the frame in the current page, the name value of the new window, or the name value of the new label.
    [Supplementary explanation]
    window.open( url,target,init); //URL represents the page address;
    Target represents the target frame

1. Open the link in a new tab/page

window.open(‘http://www.wlzhys.com‘,’target’,”);

2. Open the link in the current page

(1)window.open(‘http://www.wlzhys.com‘,’_self’,”);
(2)window.location.href=’http://www.wlzhys.com‘;

Guess you like

Origin blog.csdn.net/weixin_40362806/article/details/131050411