Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window.open() is blocked by browser when is called from promise

I have code like this:

window.open('https://api.instagram.com/oauth/authorize/',
'_blank',
'width=700,height=500,toolbar=0,menubar=0,location=0,status=1,scrollbars=1,resizable=1,left=0,top=0,modal=yes');

This works fine when is called from any place of code, but when I use it in promise (see below), it is always blocked by browser. Any suggestions?

action().success(function (r) {
  // window.open(...);
}

Promises are from angular.

like image 803
mmisiarek Avatar asked Apr 25 '14 08:04

mmisiarek


People also ask

Is window open synchronous?

Using Chrome's window. Native window. open() allows synchronous access to opened windows so it is convenient choice if you need to open a dialog or a preferences window.

How to block pop ups JavaScript?

A secure way to block popups is to specify a sandbox using the content security policy header. Content-Security-Policy: sandbox allow-scripts; In sandbox mode a lot of functionality is disabled, including popups: allow-popups: Allows popups (like from window.

What is window open js?

open() The open() method of the Window interface loads a specified resource into a new or existing browsing context (that is, a tab, a window, or an iframe) under a specified name.


1 Answers

            var newTab = $window.open('', '_blank');
        promise
            .then(function () {
                var url = '...';
                newTab.location.href = url;
            });
like image 83
rose luo Avatar answered Sep 28 '22 10:09

rose luo