我们正在实现OAUTH身份验证进行登录。在我的应用程序中单击链接后,它将重定向到打开登录页面的浏览器。该页面是使用Jade / pug配置的,并使用Express js使用表单验证和路由机制来实现。
但是在尝试使用关闭按钮关闭浏览器窗口时,出现以下错误:
Scripts may close only the windows that were opened by it
form(name="myForm", action="/login",method="POST",novalidate)
divForm
divw1
.group
input(type='number', required='', name="userid",autocomplete="off", data-required-msg='Username is required')
label Enter User ID
divw1
.group
input(type='password', required='', name="password")
label Enter Password
divButtons
input(type="button",value="CANCEL",onClick='onBtnClk()',ID="cancel")
input(type="submit",value="LOGIN",ID="login")
var express = require('express');
var router = express.Router();
router.post('/', '', function(req, res, next) {
if (req.body.userid === '' && req.body.password === '') {
// Looks like the user not provided credentials, let's show the ui again...
res.render('login', {
error: 'User ID and Password are mandatory'
});
return;
}
});
function onBtnClk(){
window.top.close(); //window not closing(Scripts may close only the windows that were opened by it)
}
答案 0 :(得分:0)
这个问题与帕格无关, 关于JavaScript API。 该API仅允许您的脚本关闭由脚本打开的窗口, 参见here。
只要脚本未打开您的窗口,您将无法关闭它,这意味着您应该告诉用户登录成功并且他们可以关闭窗口