What triggers the popup blockers in browsers? - javascript

In what circumstances do blockup blockers in browsers activate, and in what circumstances do they not?
Can you ever use an onclick event on a link to trigger a popup (other than target = _blank) or will that always trigger the blockers?

Most popup blockers are triggered when a popup is launched indirectly from a user action.
Some popup blockers are triggered when a user clicks, but most are not. Basically, if the popup is triggered within a click handler (or code that it calls), you are generally okay.
If possible, I would recommend avoiding popups entirely. They tend to disrupt the user experience, with a few exceptions.

Here is a pretty detailed answer about pop-ups. Yes you can use an onclick event to trigger a popup and generally that's how ad companies make money -- they track your click to know you have seen the pop-up ad and count it so the people sending the pop-up to you get money.
Also here is a pretty detailed article on how pop-up blockers work.

Related

show custom popup on page refress and browser/tab close in javascript/jquery

I want to open popup when closing the tab or browser first time and get the user review. I used onbeforeunload(), but I need to handle page refresh and tab close deferent different event.
Short answer: You can't.
Longer answer: For rather obvious "security" reasons it is very limited what you can do when a user tries to navigate away from a page / close a tab or in any other way leave the site.
The reason is that browsers want to make absolutely sure that you cannot prevent the user from closing a tab or window that he / she wants to close.
Therefore the onbeforeunload javascript event - and by extension the beforeunload jQuery event - are extremely limited in what they can do. One of the things they definitely cannot do is prevent the page from closing - except using one very standardized and rather boring method the browser (usually) allows.

Allow popup in Greasemonkey script [duplicate]

How to make pop up blockers allow your popup windows?
In general, by popping them up from within the event handler of a user-generated event. For instance, if you have a link and the user explicitly clicks it and you raise a popup from the onclick handler on the link, most popup blockers will allow the popup because of the user's explicit action. In contrast, popups from the window.load event, or code executing as a result of a setTimeout or setInterval call, will typically be suppressed.
Somewhat OT, but: If you can avoid using a pop-up, I would. I'd say (unscientifically) that 95-99% or so of the use-cases where people think they need a pop-up, there's a better design solution. But the answer above is there for those 1-5% situations. :-)
You should use a jQuery UI Dialog, which the popup blocker will not affect.
Users have to set that manually. Imagine what would happen if web apps were allowed to override popup blockers.
You can't. It's up to the user to configure their software to allow pop ups. As a general rule, pop ups generated by user input (i.e. clicking on a button) is usually allowed by most pop up blockers. But this isn't a definitive rule and we can't change it programmatically. If we could it would make pop up blockers useless.
Display a message nicely asking the user to unblock your popups. Obviously the whole point to popup blockers is so you, the site developer, can't forcibly defeat them.
One solution is to make them appear on your page rather than as an actual pop-up (which you can do pretty easily with jquery). If that's not appropriate in your case, asking nicely is a good option.
In your own browser … it depends on the browser and/or third party popup blocker.
When you have no control over the client — open the popup in response to a user generated event (such as onclick).

How to allow popups when url loads if it is NOT a physical click by the user in js

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

What user actions trigger beforeunload in which browsers?

closing window
refreshing page
clicking on a link
??
It seems to be inconsistent. (I'm shocked!) Is there a list somewhere? I'm particularly interested in Firefox, but am curious about others, as well. The Mozilla docs are vague:
window.onbeforeunload
An event that fires before the unload event when the page is unloaded.
window.onunload
The unload event is raised when the document is unloaded.
Gee, thanks.
window.onbeforeunload will trigger before you navigate to away from current page (from URL address, BACK button, close browser, etc.)
The event will not fire in Opera. But all the other browsers seem to respect it OK.
I have used this in the past for AJAX-intensive sites, mostly as a way to avoid having to support the BACK button.
It also works well as a confirmation dialog to prevent you from accidentally losing your work. But users might get annoyed by the confirmation. So this might not be a good enough reason to use it.

Google Toolbar prevents open a new window

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.

Categories