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

2023-09-30前端开发问题
1

本文介绍了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 弹出窗口被阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

Fatal error: Call to a member function fetch_assoc() on a no
业务场景:使用update语句去更新数据库字段。 原因:update接收值不正确。原来代码: $query = "UPDATE student SET date = now() WHERE id = $id";$result = $mysqli-query($query2) or die($mysqli-error); // 问题出现了在这句 $data = $result-fetch_ass...
2024-12-13 前端开发问题
136

layui实现laydate日历控件控制之前日期不可选择
具体实现代码如下: laydate.render({ elem: '#start_time', min:0, //,type: 'date' //默认,可不填}); 只要加一个min参数,就可以控制了。0表示之前的日期不可...
2024-11-29 前端开发问题
133

如何使用百度地图API获取地理位置信息
首先,我们需要在百度地图开放平台上申请一个开发者账号,并创建一个应用。在创建应用的过程中,我们会得到一个密钥(ak),这是调用API的凭证。 接下来,我们需要准备一个PHP文件,以便可以在网页中调用。首先,我们需要引入百度地图API的JS文件,代码如下...
2024-11-22 前端开发问题
244

ajax请求获取json数据并处理的实例代码
ajax请求获取json数据并处理的实例代码 $.ajax({ type: 'GET', url: 'https://localhost:44369/UserInfo/EditUserJson',//请求数据 data: json,//传递数据 //dataType:'json/text',//预计服务器返回的类型 timeout: 3000,//请求超时的时间 //回调函数传参 suc...
2024-11-22 前端开发问题
215

js删除数组中指定元素的5种方法
在JavaScript中,我们有多种方法可以删除数组中的指定元素。以下给出了5种常见的方法并提供了相应的代码示例: 1.使用splice()方法: let array = [0, 1, 2, 3, 4, 5];let index = array.indexOf(2);if (index -1) { array.splice(index, 1);}// array = [0,...
2024-11-22 前端开发问题
182

layui 实现实时刷新一个外部的div
主页面上显示了一个合计,在删除和增加的时候需要更改这个总套数的值: //html代码div class="layui-inline layui-show-xs-block" style="margin-left: 10px" id="sumDiv"spanSOP合计:/spanspan${totalNum}/spanspan套/span/div 于是在我们删除这个条数据后,...
2024-11-14 前端开发问题
156