gpt4 book ai didi

javascript - 一键登录

转载 作者:行者123 更新时间:2023-12-02 16:36:46 24 4
gpt4 key购买 nike

我有一个login页面,如果密码正确,将打开实际页面(另一个网址)。

这是我运行的脚本:

<script>
var dataGlobal;
$('#in1').click(function(){
var reply = prompt("Password", "");
if(!reply) return; // user pressed cancel
$.post('/~std10093/scheduler_pass.php', {elements: reply}, function(data) {
if(data != "not")
alert("Password ok, press the second button to enter scheduler");
else
alert("prits");
dataGlobal = data;
});
});
$('#in2').click(function(){
window.open(dataGlobal);
});
</script>

现在用户必须单击第一个按钮,输入密码,然后单击另一个按钮,这将打开新的 URL。我只想用一个按钮来完成此操作,可以吗?

如果我修改上面的代码并将 window.open(dataGlobal); 移动到 if(data != "not") 的主体中(这是如果密码正确,我们将进入该正文),Firefox 将阻止加载新页面,因为它会阻止弹出窗口。

enter image description here

在上图中,人们还可以看到我之前提到的两个按钮。

<小时/>

理想情况下,我想将 window.open() 替换为不会触发弹出窗口预防的内容。

<小时/>

编辑

我想要实际页面的另一个网址。实际页面是来自 here 的调度程序,它是公开的,因此登录的 url 也是公开的。但是,我希望调度程序的 URL 是私有(private)的,以便我信任的人无需登录即可访问它。

最佳答案

与其创建弹出窗口,为什么不直接使用当前窗口?

在这种情况下更改为:

 $('#in2').click(function(){
window.location.href = dataGlobal;
});

编辑:- 可以移动到回调:

<script>
var dataGlobal;
$('#in1').click(function(){
var reply = prompt("Password", "");
if(!reply) return; // user pressed cancel
$.post('/~std10093/scheduler_pass.php', {elements: reply}, function(data) {
if(data != "not")
window.location.href = data;
else
alert("prits");
});
});
</script>

关于javascript - 一键登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27865209/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com