简体   繁体   English

如何停止执行其他JavaScript事件

[英]How to stop further JavaScript events from executing

I'm using an Infragistics grid on a form and am handling multiple client-side events on the cells (eg cell click, before cell edit, before cell update, etc). 我在表单上使用Infragistics网格,并且正在处理单元格上的多个客户端事件(例如,单元格单击,单元格编辑之前,单元格更新之前等)。

On the cell click event, I'm spawning a secondary window (successfully) as follows: 关于单元格单击事件,我正在按如下方式成功生成一个辅助窗口:

 var convChartWindow = window.open("conversioncharts/" + currentCell.getValue() + ".html", "chart", "location=0,0, status=1, scrollbars=1, width=" + screen.width + ", height=175");        
 convChartWindow.focus();

However, the 'convChartWindow' does not maintain the focus, and gets covered with the parent window. 但是,“ convChartWindow”不保持焦点,而是被父窗口覆盖。 None of my other cell events fire after this, but there seems to be some Infragistics JavaScript that runs. 此后,其他所有单元事件均未触发,但似乎运行了一些Infragistics JavaScript。

Is there a something I can put after the .focus() above to prevent further javascript from running and keep the focus on the correct window? 我可以在上述.focus()之后添加一些内容,以防止进一步的JavaScript运行并保持焦点在正确的窗口上吗?

Thanks! 谢谢!

Call this: 叫这个:

// Prevents event bubble up or any usage after this is called.
// pE - event object
function StopEvent(pE)
{
   if (!pE)
     if (window.event)
       pE = window.event;
     else
       return;
  if (pE.cancelBubble != null)
     pE.cancelBubble = true;
  if (pE.stopPropagation)
     pE.stopPropagation();
  if (pE.preventDefault)
     pE.preventDefault();
  if (window.event)
     pE.returnValue = false;
  if (pE.cancel != null)
     pE.cancel = true;
}  // StopEvent

This was snipped from here: What is equivalent of 'event.returnValue=false' in Firefox 这是从此处摘录的:在Firefox中等效于'event.returnValue = false'

and was written by Peter Blum 由彼得·布鲁姆(Peter Blum)撰写
See: PeterBlum.com 参见: PeterBlum.com

i dont know what infragistics is. 我不知道什么是基础设施。 ill assume its some framework over which you have no control. 不能假设它是您无法控制的某个框架。 if i were you i would try the following: 如果我是你,我将尝试以下操作:

1) set a timeout to take focus back to the window after 1000 ms, or set a timeout loop to set focus to the window you need. 1)设置超时以在1000毫秒后将焦点移回到窗口,或者设置超时循环以将焦点设置到所需的窗口。 this is a hack. 这是一个hack。

2) figure out what functions fire the events that ruin your life, override those functions in your code and add a flag that will prevent them from doing something evil 2)找出哪些函数引发了破坏您生活的事件,在代码中覆盖了这些函数,并添加了一个标志,以防止它们执行不良操作

3) last, atleast read this: http://www.quirksmode.org/js/events_order.html there might be something useful for you in there 3)最后,至少请阅读以下内容: http : //www.quirksmode.org/js/events_order.html那里可能对您有用

让子窗口在焦点打开时自动调用焦点。

If there is something else in the function that runs the code you gave, try using: 如果函数中还有其他内容可以运行您提供的代码,请尝试使用:

break;

after: 后:

convChartWindow.focus();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM