Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
545 views
in Technique[技术] by (71.8m points)

javascript - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
            var newTab = $window.open('', '_blank');
        promise
            .then(function () {
                var url = '...';
                newTab.location.href = url;
            });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...