i'm writing a extension, which needs to call some JS from the current tab/document when user closes this tab (some saving etc). document.onbeforeunload doesn't do it for me, because it's also called when the page is reloaded. I'm looking for something like tryToClose but for tabs.
You need to listen to "TabClose" event within the extension as illustrated at Notification when a tab is added or removed
I'm able to catch the event. Any pointers on how to prevent the closing of the tab? I attempted event.stopPropagation() on the handler code. It does not stop the closing of the tab!
Related
I'm writing a VBE/VBIDE add-in and I have a tool window that changes based on the open CodePane objects. Is there an event I can monitor when a code pane is added or removed from the CodePanes collection?
The CodePanes collection itself appears to have no Events associated with it.
If there is no event available, I'm open to other workarounds. Polling would be a reliable fallback, but I'd rather not go that route if I could avoid it.
I'm facing an issue with inputs loosing focus. The issue is like this:
I send an AJAX request to load a form, when loaded I display it with in a modal.
Now if I click on any of the inputs it gains focus and blurs immediately, so I need to click it again (and this time it stays focused).
I need a tool that traces the event flow and dispatching in Firebug's console (or some similar tool), so that I can detect the culprit for this odd behavior and fix it.
I have tried Eventbug and FireQuery; but I haven't be able to find the code that causes this.
You may go to scripts panel of Firebug, then hover your mouse over the input, then click ALTCTRLB from the keyboard to activate "Break on next", then click the input, and it should hit a breakpoint in the onclick handler of the input, then you can go through the code to find potential calls that cause blur (provided that you don't do any aggressive polling via setInterval/setTimeout in your javascript for some reason, or the framework you use doesn't; then it'll likely pause in that code).
You may also want to execute some code at the very beginning of the page to override the addEventListener method so that you hijack it: log any calls to it, and forward execution to the original function; see slides 13-14 of my presentation (I do it in Greasemonkey, but it's not relevant here; just make sure this is executed at the very beginning of the page).
I want to disable the RightClick>Reload functionality in Firefox.
I know that it cannot be done through js running on a specific web page.
How to disable it entirely for the browser? (Assuming I can alter the browser behavior)
Is it possible to create a manual patch/addon that makes this change in the Firefox code base?
The browser window contains three <command> elements related to reloading pages: Browser:Reload, Browser:ReloadOrDuplicate, Browser:ReloadSkipCache (I didn't bother figuring out how these are triggered). The first one is the only important one because the other two will disable automatically if it is disabled (they contain the corresponding <observes> element). So your extension would need to run the following code in the browser window:
document.getElementById("Browser:Reload").setAttribute("disabled", "true");
Only problem is that the browser window itself will also disable/enable this command, from the onLocationChange() method of its progress listener (the command should be disabled for about:blank). I guess that the solution is to register your own progress listener do the same thing in the onLocationChange() method (your listener should be called after the browser's because it is registered later).
If you do it via a XUL overlay, you can completely disable it:
<command id="Browser:Reload" oncommand=""/>
<command id="Browser:ReloadOrDuplicate" oncommand=""/>
<command id="Browser:ReloadSkipCache" oncommand=""/>
Then you don't need to add a listener.
You don't have to reinvent the wheel. Use Menu Editor. I've been using it for ages. Should be enough.
Install it, open settings, choose Main context menu from dropdown. Find Reload and uncheck it. Voila.
I've followed the Google app script tutorial here which is a very simple script with two functions. showDialog (which presents a dialog box with a text field and submit button ) and respondToSubmit(e) which handles the submit button and adds the entered data to the spreadsheet.
It works fine.
What doesn't seem to work is the debugger on the callback. So I place a breakpoint in both functons and start the showDialog function. The debugger kicks in and stops execution at the breakpoint. I click continue so I can interact with the newly opened dialog box. However when I click the submit button the debugger does not start again. The respondtoSubmit(e) function is executed. The debugger just does not stop on the breakpoint(s).
Is there a problem with debugging callbacks like this or can you only debug one function at a time?
For reference Utilities.jsonStringify(e) is depricated, use JSON.stringify() and JSON.parse() instead.
As of right now, the debugger has some unexpected behaviours. Mostly, it seems to only respect breakpoints during calls from the script editor, so to debug your event handler you must call it from the debugger, not the UI. If you need to peek into variables such as the event object passed to the function, for example, try adding this line to your handler where you'd normally put a breakpoint:
Logger.log(Utilities.jsonStringify(e));
Then view the log from the script editor after execution.
It seems to me that the Logger does not work either, unless run from the script editor. I did manage Browser.msgbox(Utilities.jsonStringify(e)) which had brought the (expected) result:
{"parameter":{"clientY":"45","clientX":"37","eventType":"click","ctrl":"false","meta":"false","source":"u12053277590","button":"1","alt":"false","myTextBox":"babi","screenY":"381","screenX":"598","shift":"false","y":"13","x":"33"}}
I wanted to add an event for a textbox to handle when it loses focus. I was sure I remembered some sort of LostFocus event, but I didn't see it in the Properties grid. But sure enough, the event exists if I access it programmatically. I'm using VS2008 - any reason why this event (and maybe others?) wasn't shown in the Properties grid?
Control.LostFocus is marked with [BrowsableAttribute(false)]. This means it will not be shown in the Properties window. For details see BrowsableAttribute.
Here's the declaration:
[BrowsableAttribute(false)]
public event EventHandler LostFocus
LostFocus is a troublesome event, this is the fine print from the SDK docs for WM_KILLFOCUS, the underlying Windows message:
While processing this message, do not make any function calls that display or activate a window. This causes the thread to yield control and can cause the application to stop responding to messages. For more information, see Message Deadlocks.
Use the Leave event instead.