When I use JavaScript function
var w = window.open('about:blank');
under FireFox the popup is blocked and I get the option to unblock it. Even if I do this the popup does not appear (I believe the JavaScript needs to be fired one more time).
But I need to be sure that the popup fires even when the code runs for the first time.
So what I want is to check whether FireFox allows popups. There are two possibilities:
This should be done in such a way that if it does not allow then show appropriate message and wait (setTimeout?) until the access is granted (and open popup afterwards).
Before doing this window.open operation check if FireFox allows popups. If it does not, then show appropriate message (and do not allow the user to go deeper inside app without granting access) but if it does allow then do not open the popup (user does not need to see that he can fire popups). All of this can be done for example when user logs in (all of main popups require the user to be loged in).
So that's the idea. But what about JavaScript? How can I achieve this? Is it even possible?
When firefox blocks a popup, the reference to w will be null.
So my suggestion:
Try to open the popup
check if w is null
when w is null, show the message
put an element into the message with a notice like "click here to open the window"
observe the click-event of this element, when it fires, open the popup(firefox usually will not block a popup forced by a click-event) and hide the message
otherwise: hide the message after xxx seconds
Other ideas:
observe the click-event of the document and open the popup then when it's open yet(and remove the click-observation)
when the popup is null, use a modal-dialog that blocks the UI and give the user the option to open the popup via a click inside the dialog. I would prefer this, because here you have the chance to determine if the user want's to allow the popup.
don't use popups at all, when possible use inline-popups, e.g. a jquery-dialog, LightBoxes, etc.
Related
I am noticing that my share popups are being blocked on our application but not others.
Here is the code execution:
1.) User enters web page.
2.) User clicks on facebook or twitter or googleplus share icon
3.) Onclick event passes the request to an internal controller that saves some information and then redirects back to the originating webpage. This time, however, there is a request parameter that invokes the usage of opening a new window.
The code I have that invokes opening a new window is (for this example we will use facebook):
var url = 'https://www.facebook.com/sharer/sharer.php?u='+copyLink;
window.open(url,'newwindow','width=600,height=600');
Now, if i enable popups it works fine. The problem is the user has to enable popups every time.
Is it a server issue? What is the reason why on other apps they don't have blocked popups but for OUR APP we cannot use popups without enabling popups
Any help would be greatly appreciated.
From what I understand, your application attempts to open a popup window following a page load. The nytimes.com popup appeared in response to a mouse click.
There is an important difference between these two ways to open a popup: the latter follows a user-initiated action but the former does not. As a result, popup blockers will generally block the former but not the latter. A lot of users wouldn't be too surprised if a popup opened when they clicked a button, but they would be more irritated if a popup appeared when a page loaded. The fact that your popup was ultimately triggered by an action on another page doesn't matter - what happens if you manually add to the URL the extra parameter that opens the popup?
Here's an old page on MSDN on popup blockers. It may describe the popup blocker in IE6 (of all browsers), but I think it still provides a reasonable explanation of when popup blockers typically permit or block popups.
Would it be possible to open a popup for your share dialog before calling back to the server? I would expect that opening a popup in the onclick handler would work without needing to explicitly allow popups.
I want to allow popups when site loads and if the root cause of an event is NOT a physical click by the user, then it's getting blocked. any help
My code:
$("#buttonBtn").on('click',function(){
openpopup('temp'+id)
});
$("#buttonBtn").trigger('click');
Thanks in advance
With this, if you explicitly click, popup appears. If user comes to this button via keyboard and press Enter or something, I guess this would not be triggered.
$("#buttonBtn").click(function(e){
e.preventDefault();
// some job you will do if clicked, for example, open popup
});
Great example here
You can generally open popups by using window.open. However, most browsers have built-in popup blocker where the user will be notified about a popup and will be asked if he really wants to show it.
The MDN has an informative article about window.open. It also gives some information about popup blockers:
How can I tell when my window was blocked by a popup blocker?
With the
built-in popup blockers of Mozilla/Firefox and Internet Explorer 6
SP2, you have to check the return value of window.open(): it will be
null if the window wasn't allowed to open. However, for most other
popup blockers, there is no reliable way.
Source: https://developer.mozilla.org/en-US/docs/DOM/window.open
In my MS CRM 4.0-application, there are several things to do before the window is closed.
So I have to stop the window from closing in the onbeforeunload-function and do my stuff in different locations.
This works already, but only if I show the dialog by returning some message in my onbeforeunload-function and the user chooses "stay on page" (or something like this)
Is it possible to skip this dialog and stop the window from closing?
I know there are several reasons, why this shouldn't work, but, e.g. in my CRM-application it is neccessary.
I am working on a small extension for personal consumption and practice. What I would like to do is provide some information every time Firefox starts using a modal dialog. I know this is generally frowned upon, but this is mostly for know-how. I have a few question regarding some things---I feel like there are better ways to do them. Kindly share your wisdom:
I have created a small dialog XUL, and I have an event listener registered to the load event of the main window. To actually display the dialog, I use:
window.openDialog("chrome://myext/content/prompt.xul", "dialogname",
"chrome,dialog,modal,centerscreen,resizable", params).focus();
Problem 1: I can never get the start up dialog to be on the center screen (even if I have centerscreen enabled), it starts top left---it would be nice to have it in the middle---something like Firefox's password-on-startup request. How can I achieve that?
I would like the modal window to open only once per session, even if there are multiple instances of Firefox. What I have done to accomplish that is, once the dialog runs, I set an extension preference, and I check that before opening another dialog on the "load" event of any new window.
Problem 2: To make sure I somehow don't have preferences set from a previous session, I try to check if this is the first window opened, and if so, I reset the preferences. Just to be safe, I also reset them on the unload event of the last window that closes. To discover the first/last load and unload, I use the nsIWindowWatcher service, and see if I can traverse the returned enumerator:
var ww = Components.classes["#mozilla.org/embedcomp/window-watcher;1"]
.getService(Components.interfaces.nsIWindowWatcher);
var en = ww.getWindowEnumerator();
var win1 = en.getNext();
//if there is no more en.getNext(), then this is the 1st window
There has to be a better way to do this, no? Some event which only fires once per session (not per window) for example?
If the dialog box is cancelled, I want Firefox to close down. Right now, I accomplish that through a simple window.close() associated with the cancel button of the dialog. However, since the original load (which triggered the modal dialog) is called after the page finishes loading, I can see a small glimpse of the homepage before it closes due to window.close()---this is not elegant. Is there an event similar to "before_page_load"? What is the proper way to accomplish this goal.
Once again, this is mostly for personal use, so kindly ignore the usability factor of a startup modal dialog.
You probably need to observe the final-ui-startup notification, which happens before the main window opens. You do this by registering a component to observe the profile-after-change notification, then during that notification, add yourself to observe the final-ui-startup notification. When your component subsequently receives that notification, it can then open your modal dialog and subsequently quit the application if necessary.
Google toolbar is creating a serious problem for me in IE 6 when i try to open a window using window.open or if i set target="_blank" for anchor tag. It treats the window as pop up and dispaly pop up is blocked which i really don't want to dsiplay to my user. This problem only occurs if there is a extra code getting executed before window.open, e.g. calling another method at onclick then using window.open. Can somebody tell me how to solve this issue?
The toolbar and other devices like that are intended to protect users from unwanted popup windows. The only way for them to determine whether a window is "wanted" is to determine whether window.open is being called in an event handler for a user-initiated event, like a button click. Thus if you try to do something like call window.open on document load, or in an AJAX success handler, the toolbar (and other blockers) will assume that the popup is suspect.
There's nothing you can do about this other than, as noted by Mr. Buchan, tell your users what to expect. Wherever possible, have your popups launched directly from click handlers.
A more radical change would be to shift away from window.open and use simulated popup windows made from floating elements that cover up part of the page. Something, that is, like what jQuery UI dialogs give you.
Adding the site to your Trusted Sites will work.
Setting target="_blank" shouldn't be triggering a pop-up blocker.