K
K
Konstantin T2015-09-29 10:18:40
JavaScript
Konstantin T, 2015-09-29 10:18:40

How to properly make window.open so that it is not blocked in browsers?

If you call the method

var params = (
    'width=' + width +
    ',height=' + height +
    ',left=' + left +
    ',top=' + top +
    ',scrollbars=no',
        '_blank'
);

window.open(url, 'popup', params);

That browser on the phone first opens this window, then abruptly closes and offers a choice of what to open again.
Those. in fact, it opens the window twice, the first time it opens and closes, and when the window is opened the second time, it loses its uniqueness! How to remove this bug?
ATTENTION! Window.open opens on click, not programmatically, i.e. The problem is not blocking by the browser itself.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
shagguboy, 2015-09-29
@shagguboy

do it immediately in onclick. not in other places

V
Vitaly Inchin ☢, 2015-09-29
@In4in

It may be that:

var params = ('width=' + width + ',height=' + height + ',left=' + left + ',top=' + top + ',scrollbars=no', '_blank');
//Запятая перед блэнком выступает в роли оператора. Иными словами:
//var params = '_blank';

And in general, the phone should somehow do this, because the mobile browser cannot open a new window - only a new tab. I think _blank forces you to do the first, which is why the action you described occurs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question