我正在开发纯粹在JavaScript中的OAuth身份验证流程,我想在弹出窗口中向用户显示"授予访问权限"窗口,但它会被阻止.
如何防止由不同浏览器的弹出窗口阻止程序阻止弹出窗口window.open或被window.showModalDialog其阻止?
我正在使用Smarty模板系统.其功能之一是输出脚本的可能性,该脚本为每个页面生成调试信息.在这里您可以看到生成代码的示例:
<script type="text/javascript">
//<![CDATA[
setTimeout(function() { //Attempt to fix the issue with timeout
var _smarty_console = window.open("about:blank","md5hash","width=680,height=600,resizable,scrollbars=yes");
console.log(_smarty_console); //Trying to log it
if(_smarty_console!=null) {
_smarty_console.document.write("<!DOCTY... lots of HTML ...<\/html>\n");
_smarty_console.document.close();
}
}, 5000);
//]]>
</script>
Run Code Online (Sandbox Code Playgroud)
问题是,window.open函数总是返回null.我试图延迟它setTimeout但没有改变.当我复制代码并在Firebug控制台中运行它时,它可以正常工作.页面上没有其他脚本.该页面使用严格的XHTML.脚本就在此之前</body>.
我有以下服务调用从服务器下载文件.我目前拥有它,以便PDF将在新的选项卡/窗口中打开,并且将下载任何其他文档类型.
我现在遇到的问题是弹出窗口拦截器阻止了PDF.有没有办法解决?
return formService.getForm(params)
.$promise
.then(response => {
var blob = new Blob([response.data], {
type: response.responseType
});
var fileUrl = (window.URL || window.webkitURL).createObjectURL(blob);
if (response.responseType === 'application/pdf') {
window.open(fileUrl);
} else {
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none"
a.href = fileUrl;
a.download = formName;
a.target = "_blank";
a.click();
window.URL.revokeObjectURL(fileUrl);
}
})
.catch(error => {
console.error(`Error downloading form '${formName}' `, error);
});
Run Code Online (Sandbox Code Playgroud)