How to close tabs with animation in Firefox 4? - firefox4

Moving my extension to Firefox 4, I noticed my old code closes tabs immediately :
gBrowser.removeTab(tab)
While in Firefox 4, tabs are being closed with some animation if the process was initiated by a user.
How to programmatically close tabs in the same manner?

Had the same question and found the answer somewhere else...
gBrowser.removeTab(tab, {animate: true});
And you probably already know that the preference is browser.tabs.animate.

Related

Close Firefox on click on image

I am looking for a way to close Firefox from within an html page.
When looking for a solution I saw that most pages suggested something like:
Close
This is only working for tabs and in Firefox this method does not seem to work at all.
Is there a way to close Firefox completely after clicking on a website element?
Thanks!
You can only close windows if you have their handle. That means your page needs to be the one that opened them (or you somehow passed the handle around).

Firefox 5 inactive tab jQuery animation issue

I have coded a slider to my project but it fails on chrome and firefox5.
Slider has a info bar and if page is in inactive tab, it queues the animation of infobar and when i return to the my page it repeats animation n times.
How can i fix that issue ? :(
I try: setTimeout but it couses a new bug that infobar never seems :S
The test link of my project is here : http://demo.cihanuygun.com/polo/
See this answer about how to detect the window losing and gaining focus and in your slidebox() function, don't queue up an animation if the window does not have focus.

NPAPI plugin - Mac OS - [NSAlert runModal] does not work correctly on Firefox when multiple modal dialogs are opened

I am working on some plug-in and I need user interaction during plug-in loading. Precisely, when plug-in is being loaded pop-up modal dialog is shown and user must to allow (deny) the plug-in to have access to the external devices by clicking "Allow" or "Deny".
I use Firebreath's method FB::BrowserHost::ScheduleOnMainThread to schedule function call "showPopUpAlert" on main thread and for the modal dialog I use Cocoa API calls [alert runModal] and [alert abortModal] or [alert stopModal].
When I run plug-in in one tab, do not answer by clicking on the dialog's buttons (dialog is still open) and attempt to load the plug-in again in separate tab new instance of the dialog is shown on top. Then I can not access to the first opened dialog until the second one is active.
If I click on second opened dialog Allow or Deny it will be closed and the first one will be still active.
Problem raise when I attempt to close one of the two opened tabs.
1) If I close the second opened tab their pop-up dialog will be closed and the first opened dialog beneath will be still active.
2) I attempt to close first opened tab the second pop-up dialog will be closed and the first opened will be inactive.
That is only Firefox problem, Chrome and Safari work perfectly.
On Chrome and Safari if one dialog is active whole browser is blocked and it is not possible to open new tab until the dialog is opened.
It would be great if it is possible to make Firefox to work as Chrome and Safari. Do you have any suggestions?
I've tried to access to the browser window and to use method beginSheetModalForWindow but I've read on several topics that it is not possible because plug-in and browser are running in separate threads.
My code relies on the taxilian's example, please take a look and I would be very grateful if somebody could help me.
Regards,
l3r
Sorry if I was unclear.
I have sample web app which use the plug-in.
When I run the sample app one modal dialog (NSAlert) is shown with a question: "Do you allow the plug-in to access to your external devices?"
The question could be answered by clicking on "Allow" or "Deny" button.
1) I run sample app in Firefox in one tab and do not answer the question, the modal dialog stays on top.
2) I open one new tab and run the sample app again, new modal dialog is shown. Now two modal dialogs appear one in front of other.
3) If I close the tab opened in 1), the modal dialog from 2) will be closed, and the modal dialog from 1) will stay inactive (It is not possible to answer the question).
I would like to prevent browser (Firefox) from opening new tab if one modal dialog have previously been opened, or if I close one tab I would like their modal dialog to be closed not the other one which is on top.
Is it possible? Do you have some suggestions?
I hope I have been a bit more clear.
Regards,
l3r
Based on your updated text, it sounds like what you really are asking is how to prevent more than one tab from opening a modal dialog.
Basically, what I would recommend is to create a global singleton that manages the dialog; put a YourAPIWeakPtr on it to reference what it should call back (or something similar) and then check if another dialog is open before allowing anything to open a second one.
You could either then reject the old one and close the dialog or you could ignore future requests when a new request comes in and an old is still open.
Remember that you're still in the same process for all instances of the plugin, so it's just a question of making sure that the resource can only be used once per process.
It's not actually possible for a dialog to be truly modal from an NPAPI plugin; modern browsers run plugins in a separate process (not thread), and OS X doesn't have a way to make dialogs modal across applications. Instead, each browser approximates the behavior.
You could file a bug against Firefox, and perhaps they could handle this case differently, but fundamentally the design is flawed: using modal dialogs from plugins is strongly discouraged, and there's no guarantee that it will work correctly.
A better solution would be not to use modal dialogs at all, and put whatever UI you need within your plugin's bounds, as NPAPI plugins are intended to be used.

Disable navigation swipe on Chrome browser in javascript [duplicate]

This question already has an answer here:
Stop chrome back/forward two finger swipe
7 answers
On Chrome Mobile, Google introduced a tab navigation with the swipe left/right events.
But i have a webapp, and i implement a swipe left event to open my navigation menu (like facebook or spotify)
The problem is, if user start his swipe on the first left pixel (left:0), the browser start the navigation mode, and do not execute my opening menu function.
Is there a way, to disable or stop the navigation mode on Chrome ?
I already tried with .preventDefault, and stopPropagation function, but not working :(
Thanks for your help
Could you try using a combination of:
intercepting the browser Back function using window.onbeforeunload, as per this example, and
disabling navigation using the technique illustrated in this example?
This behaviour is built into the java source of chrome (probably), which is why I think it won't be possible to disable this behaviour with Javascript alone. Maybe you can distribute you app with phonegap, if this behaviour is necessary.

How to get tabs before Chrome browser window closed?

I'm using Google Chrome Extensions and I was trying to capture all the tabs before a window is closed as such:
chrome.windows.onRemoved.addListener(function(windowId) {
chrome.windows.get(windowId, function(window) {
alert(window.tabs);
});
});
But I think the window is actually getting destroyed before I can get to window.tabs. How would I get their ids before the window is removed?
Thanks!
You are right, in Chrome when you close a Window, all the tabs will close first, then after that the window itself will close.
If you want to capture all the tabs before a window is closed, I believe as far as I know, the best approach will be hooking up a listener to to the tabs onRemoved event http://code.google.com/chrome/extensions/tabs.html#event-onRemoved
You would have to maintain an internal cache of what is being closed, and when a window is closed, you read that cache. It might get tricky, and some problems that you need to solve.
For example, How would you know all those tabs are being closed? Perhaps the answer to that question is to make a timer of 1 second, and count all the closed tabs in that state, and reset it once the timer has ended. There might be other ways.
Hope that helped, good luck!

Resources