如何阻止执行进一步的JavaScript事件

时间:2022-12-05 11:49:17

I'm using an Infragistics grid on a form and am handling multiple client-side events on the cells (e.g. 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. None of my other cell events fire after this, but there seems to be some Infragistics JavaScript that runs.

但是,'convChartWindow'不会保持焦点,并且会被父窗口覆盖。在此之后,我的其他单元格事件都没有发生,但似乎有一些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!

4 个解决方案

#1


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:

我不知道什么是infragistics。我假设它有一些你无法控制的框架。若我是你,我会尝试以下方法:

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. this is a hack.

1)设置超时以在1000毫秒后将焦点恢复到窗口,或设置超时循环以将焦点设置到您需要的窗口。这是一个黑客。

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那里可能有一些对你有用的东西

#2


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
See: PeterBlum.com

由Peter Blum撰写:PeterBlum.com

#3


Have the child window call the focus itself when it opens.

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

#4


If there is something else in the function that runs the code you gave, try using:

如果函数中还有其他内容运行您提供的代码,请尝试使用:

break;

after:

convChartWindow.focus();

#1


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:

我不知道什么是infragistics。我假设它有一些你无法控制的框架。若我是你,我会尝试以下方法:

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. this is a hack.

1)设置超时以在1000毫秒后将焦点恢复到窗口,或设置超时循环以将焦点设置到您需要的窗口。这是一个黑客。

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那里可能有一些对你有用的东西

#2


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
See: PeterBlum.com

由Peter Blum撰写:PeterBlum.com

#3


Have the child window call the focus itself when it opens.

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

#4


If there is something else in the function that runs the code you gave, try using:

如果函数中还有其他内容运行您提供的代码,请尝试使用:

break;

after:

convChartWindow.focus();