在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
最满意答案
尝试选择...案例陈述。
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 ...
-
如果然后在vba声明(If then statement in vba)[2022-08-21]
你不需要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 ... -
使if语句更短(Make an if statement shorter)[2022-03-03]
您可以使用绝对值缩短它: $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 ... -
VBA通配符声明(VBA wildcard statement)[2022-08-19]
这样的东西指向你的目录,找到所有匹配“ - .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]###-## ... -
这个陈述更短/顺序(this statement shorter / order by)[2022-07-29]
如果您想要同一列中的所有数据,那么您可以在其周围放置一个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:'出错'声明安全(Vba: ‘On error’ statement safety)[2023-03-01]
VBA代码可以通过多种方式中断,有些甚至不会涉及一个聪明的用户,它会破坏MsgBox并点击“ 停止”按钮:如果主机崩溃了与您的代码完全无关的内容(一些KB更新会浮现在脑海中),在程序执行过程中,您的错误处理程序将不会被跳入,并且您无法阻止它。 请勿篡改用户的本地设置。 修改你的代码。 我已经知道我可以使用String = Replace(Number, ",", ".")转换我的所有数字String = Replace(Number, ",", ".") 您的代码将数字视为字符串,反之亦然。 如果数字来自工 ... -
如果和VBA中的ElseIf声明(If and ElseIf Statement in VBA)[2021-09-16]
您的代码应用了太多测试。 您可以将此简化为以下内容: 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 ...