首页 \ 问答 \ 在JavaScript中打开新的浏览器窗口而不激活它(Open new browser windows in JavaScript without making it active)

在JavaScript中打开新的浏览器窗口而不激活它(Open new browser windows in JavaScript without making it active)

我有一些JavaScript进行AJAX调用,如果调用失败,则打开一个新窗口(Firefox中的选项卡)并在该窗口中显示来自服务器的响应。 这对于调试非常方便,因为错误通常来自Pylons,所以它是一个完整的HTML页面。

唯一的问题是新选项卡成为活动选项卡,这将完全混淆普通用户。 有没有办法打开标签/窗口,但没有让它激活,即。 保持当前活动窗口?

我的代码目前看起来像这样:

    errorWindow = window.open("", "TCerrorWindow")
    if (errorWindow)
        errorWindow.document.write(xhr.responseText);

I have some JavaScript that makes an AJAX call and, if the call fails, opens a new windows (tab in Firefox) and displays the response from the server in that window. This is very convenient for debugging, because the error is typically from Pylons, so it's a full HTML page.

The only problem is that the new tab becomes the active tab, which would totally confuse a regular user. Is there any way to open the tab/window, but not make it active, ie. keep the current active window?

My code currently looks like this:

    errorWindow = window.open("", "TCerrorWindow")
    if (errorWindow)
        errorWindow.document.write(xhr.responseText);

原文:https://stackoverflow.com/questions/1542002
更新时间:2022-06-24 16:06

最满意答案

尝试选择...案例陈述。

Dim rws As Long, rcnt As Long, crc As String

With Worksheets("Raw")
    rcnt = .Cells(.Rows.Count, "I").End(xlUp).Row
    For rws = rcnt To 2 Step -1
        Select Case LCase(.Cells(rws, "I").Value2)
            Case "admin cancellation", "building sold / management co changed", _
                 "contract renewal delayed", "system decommissioned", _
                 "building demolished", "cancelled due to credit hold/risk"
                 .Rows(rws).EntireRow.Delete
        End Select
    Next rws
End With

删除行时,您应始终从下到上循环,否则当您删除并迭代到下一行时,您有可能跳过一行。 重复使用保留字作为变量名是'坏习惯'。 在For ... Next循环中改变迭代变量的值也被认为是“不好的做法”。


Try a Select... Case statement.

Dim rws As Long, rcnt As Long, crc As String

With Worksheets("Raw")
    rcnt = .Cells(.Rows.Count, "I").End(xlUp).Row
    For rws = rcnt To 2 Step -1
        Select Case LCase(.Cells(rws, "I").Value2)
            Case "admin cancellation", "building sold / management co changed", _
                 "contract renewal delayed", "system decommissioned", _
                 "building demolished", "cancelled due to credit hold/risk"
                 .Rows(rws).EntireRow.Delete
        End Select
    Next rws
End With

You should always loop from bottom to top when deleting rows or you risk skipping over one when you delete and iterate to the next row. It is 'bad practice' to reuse reserved words as variable names. It is also considered 'bad practice' to change the value of the iteration var in a For .... Next loop.

相关问答

更多
  • 我会使用枚举来引用列号。 枚举位于代码模块的顶部。 列表中的下一个枚举是从前一个增加1。 枚举列的最大优点是需要重新排序列时; 您只需更新枚举,您的代码将像以前一样运行。 枚举也适用于智能感知。 Option Explicit Public Enum Cols cnAppTransEffDate = 2 cnAppTransAmt = 4 cnAppActionCode = 5 cnAppDescr End Enum Sub FillData() ' Some ...
  • 尝试选择...案例陈述。 Dim rws As Long, rcnt As Long, crc As String With Worksheets("Raw") rcnt = .Cells(.Rows.Count, "I").End(xlUp).Row For rws = rcnt To 2 Step -1 Select Case LCase(.Cells(rws, "I").Value2) Case "admin cancellation", "b ...
  • 你不需要ElseIfs。 如果要测试所有条件,请单独测试它们 If Label1 = 0 Then btn1.Enabled = False End If If Label2 = 0 Then btn2.Enabled = False End If If Label3 = 0 Then btn3.Enabled = False End If If Label4 = 0 Then btn4.Enabled = False End If You don't need the ElseIfs. If you w ...
  • 您可以使用绝对值缩短它: $b = abs($a); if ($b <= 2) { echo "standard"; } else if ($b <= 4) { echo "thin"; } else if ($b <= 8) { echo "super thin"; } You can shorten it by using the absolute value: $b = abs($a); if ($b <= 2) { echo "standard"; } else i ...
  • 这样的东西指向你的目录,找到所有匹配“ - .csv”的csv文件,第二阶段检查打开匹配你想要的文件模式的第一个文件 Sub LoopThroughFiles() Dim StrFile As String Dim bFound As Boolean Dim WB As Workbook StrFile = Dir("c:\temp\*-*.csv") Do While Len(StrFile) > 0 If StrFile Like "[A-Z]###-## ...
  • 如果您想要同一列中的所有数据,那么您可以在其周围放置一个SELECT ,然后执行ORDER BY 。 Select S_name As Names from Supplier JOIN Nation ON Supplier.S_nationkey = Nation.N_nationkey JOIN Region on Nation.n_regionkey = region.R_regionkey Where Region.r_ ...
  • 喜欢这个? using (var db = new DataClasses1DataContext()) 要进一步缩写,你可以这样做: using (var db = DataClass.DB()) DataClass有一个静态方法DB,它返回数据上下文的新实例。 Like this? using (var db = new DataClasses1DataContext()) To abbreviate it even further you could do something like thi ...
  • VBA代码可以通过多种方式中断,有些甚至不会涉及一个聪明的用户,它会破坏MsgBox并点击“ 停止”按钮:如果主机崩溃了与您的代码完全无关的内容(一些KB更新会浮现在脑海中),在程序执行过程中,您的错误处理程序将不会被跳入,并且您无法阻止它。 请勿篡改用户的本地设置。 修改你的代码。 我已经知道我可以使用String = Replace(Number, ",", ".")转换我的所有数字String = Replace(Number, ",", ".") 您的代码将数字视为字符串,反之亦然。 如果数字来自工 ...
  • 您的代码应用了太多测试。 您可以将此简化为以下内容: Dim copies As Long If Me.ckbPrint Then If cbxCarrier.Value = "Homestretch" Then copies = 4 Else copies = 3 End If ActiveDocument.PrintOut copies:=copies End If Your code is applying too many test ...
  • 如果你发现自己一遍又一遍地编写非常相似的代码(甚至是复制粘贴的东西),总会有一种方法来概括代码并将其放入for循环或额外的方法中。 这就是要走的路。 在你的情况下,你可以简单地使用for循环。 public static void main(String[] args) { int positive = 0; System.out.println("Input the integers at the console and press "); Scanner input = ne ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)