Javascript 在任何其他之上打开新的 window

Javascript open new window on top of any other

如果像这样打开window,同时打开记事本,记事本下方会打开新的window。

我想知道如何在任何其他 windows 之上打开一个新的 window。添加 window.focus() 无效..

    setTimeout(function() {
        window.open('http://google.com', 'google new window', 'width:10');
    }, 5000);
    

使用以下代码。我想这可能对你有帮助。

window.open('http://google.com' ,'_blank', "scrollbars=yes,resizable=yes,top=700,left=700,width=600,height=800");

试试这个 -

window.open(url, "_blank", "resizable=yes, scrollbars=yes, titlebar=yes, width=800, height=900, top=10, left=10");

The open() method creates a new secondary browser window, similar to choosing New Window from the File menu. The strUrl parameter specifies the URL to be fetched and loaded in the new window. If strUrl is an empty string, then a new blank, empty window (URL about:blank) is created with the default toolbars of the main window.

Note that remote URLs won't load immediately. When window.open() returns, the window always contains about:blank. The actual fetching of the URL is deferred and starts after the current script block finishes executing. The window creation and the loading of the referenced resource are done asynchronously.

var windowObjectReference;
var strWindowFeatures = "menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes";

function openRequestedPopup() {
      windowObjectReference = window.open("http://www.cnn.com/", "CNN_WindowName", strWindowFeatures);
    }


var windowObjectReference;

    function openRequestedPopup() {
      windowObjectReference = window.open(
        "http://www.domainname.ext/path/ImageFile.png",
        "DescriptiveWindowName",
        "resizable,scrollbars,status"
      );
    }

If a window with the name already exists, then strUrl is loaded into the existing window. In this case the return value of the method is the existing window and strWindowFeatures is ignored. Providing an empty string for strUrl is a way to get a reference to an open window by its name without changing the window's location. On Firefox and Chrome (at least), this only works from the same parent, ie. if the current window is the opener of the window you try to get an handle on. Otherwise the call to window.open() will just create a new window.

To open a new window on every call of window.open(), use the special value _blank for strWindowName.