javascript - 如何使用 JavaScript 在其他窗口之上打开一个新窗口?

标签 javascript html asp.net browser window.open

如果您打开这样的窗口并同时打开记事本,新窗口将在记事本下方打开。

我想知道如何在任何其他窗口之上打开一个新窗口。添加 window.focus() 不起作用..

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

openning window

最佳答案

试试这个 -

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.

关于javascript - 如何使用 JavaScript 在其他窗口之上打开一个新窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60202119/

相关文章:

html - 行高导致div不均匀

html - 当我将 <span> 更改为 <div> 时,文本消失了

asp.net - GridView1.HeaderRow.Cells[4].Text 和 GridView1.Columns[4].HeaderText 有什么区别?

c# - ASP.Net MVC 忽略过滤器顺序

c# - 在 ASP.NET/MVC 中验证复杂情况的最佳实践?

javascript - 如何在元素外捕捉鼠标弹起事件?

html - Flexbox - 带有 "no wrap"文本的流体列

javascript - 使用 setAttribute 方法() 的 Aurelia 自定义属性

javascript - CKEditor + Protractor : Testing with Protractor can't find CKEditor instance

javascript - JavaScript 是否有可能阻止人们右键单击以保存图像?