Angularjs $window.open 弹出窗口被阻止

Angularjs $window.open popups being blocked(Angularjs $window.open 弹出窗口被阻止)
本文介绍了Angularjs $window.open 弹出窗口被阻止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Github API 的 网络身份验证流程从 AngularJS 应用程序中.当我的注册表单提交时,我想打开一个新窗口将它们发送到身份验证页面.通常我只会在用户事件中使用 window.open 以确保它不会被弹出窗口阻止程序捕获.

I am trying to use the Github API's web auth flow from within an AngularJS app. When my signup form submits, I want to open a new window to send them to the the auth page. Normally I would just use window.open inside a user event to ensure it wouldn't get caught by a popup blocker.

在我的 Angular 应用程序中,我在 Angular 服务中封装了一些 Github api,打开窗口的代码就在其中.正因为如此,它被阻塞了.我还尝试将它放在控制器中的一个函数中,该函数由表单通过 ng-submit 调用.

In my angular app, I am wrapping a bit of the Github api in and Angular service, and the code to open the window goes in there. Because of that it gets blocked. I also tried putting it in a function in the controller that gets called by a form via ng-submit.

所以问题是,有没有一种优雅的方法可以从我的服务或控制器内部的某个地方打开表单提交的新页面,还是我需要找到另一种方法来做到这一点?

So the question is, is there an elegant way to open a new page on a form submit from somewhere inside my service or controller, or will I need to find another way to do it?

推荐答案

您无法摆脱脚本自动化 window.open 的弹出窗口阻止程序.只有真实用户的号召性用语事件才会打开一个新窗口,而不会被弹出窗口阻止程序阻止.想象一个网站的情况,浏览器中没有弹出窗口阻止程序,而 javascript 循环打开 100 个弹出窗口.你想要吗?它曾经像病毒一样在我们过去的美好时光中存在,但现代浏览器非常聪明,并且可以优雅地处理这种烦恼.

You can't get rid of the popup blocker for scripted automated window.open. Only real user's call to action events will open a new window without being blocked by popup blocker. Imagine a situation in a site where there's no popup blocker in browser and javascript opens 100 popups in a loop. Would you like it ? It used to be there in our old good times like a virus but modern browsers are much smart and this annoyance is handled gracefully.

这篇关于Angularjs $window.open 弹出窗口被阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to sort a array of object based on two properties and check the rage is sequential?(如何根据两个属性对对象数组进行排序,并检查范围是否连续?)
Untyped function calls may not accept type arguments - Angular 5 http calls(非类型化函数调用可能不接受类型参数-角度5 http调用)
ReferenceError: Excel is not defined(ReferenceError:未定义Excel)
How to save two canvas(outer and inner) as png using fabric js in angular(如何保存两个画布(外部和内部)为PNG使用织物js的角度)
Access to #39;Set-Cookies#39; header in $http(访问$http中的Set-Cookies标头)
Adding lt;stronggt;/bold text in translated string using angular-translate(使用角度翻译在翻译后的字符串中添加lt;stronggt;/粗体文本)