I got tree functions:
var a = function (f)
{
// some code
window.open("")
f();
};
var b = function (f)
{
// some code
f();
}
var c = function()
{
}
And I’m calling the functions using a chain with anonymous function:
a(function () {
b(function () {
c();
});
});
If I call the a function directly, the popup blocker does not block my popup because the window.open is triggered by a user click. But using the chain, the popup blocker blocks my popup.
How can I avoid it?
ps: It is the facebook popup, I’m not trying to do something that I’m not supposed to do.
Different browsers behave differently. I think Firefox is the strictest, only allowing popups directly generated in the same event loop as the onclick. In Chrome you can have an asynchronous call in between and it will still work. – At least that’s what I recall from memory.
The thing is, you have little control over it. It’s up to the browser to allow the popup, or not. You could develop some heuristics for each browser but that’s not ideal.
Try to find a solution that will call the
window.openin the same even loop as that is the most likely to work (if that doesn’t work it’s safe to assume nothing will work). Isa()perhaps asynchronous? Through closure you can pass the referencevar my_window = window.opengives on to any subsequent functions in case you need to add stuff to the DOM later.Example: