按钮链接加载后JS确认弹出
JS Confirm Popup after Button Link Loads
我创建了一个链接,有两个目的:(1)通过打开新选项卡将用户引导到外部链接(2)确认他们在该外部链接中执行了特定操作,并在确认时通知管理员。
我希望出现以下顺序:
- 用户点击链接并指向链接内外(即www.google.com),同时在原始页面中弹出确认消息
- 用户执行操作(或不执行)
- 用户返回到原始页面,看到一个确认弹出窗口,上面写着"请确认您执行了操作"
- 如果用户单击"确定",将调用"/dashboat/notice/admin/",并通知管理员已执行操作(这很好)
目前,我只能在用户被引导到外部链接之前出现确认弹出窗口。有没有一种方法可以立即将用户引导到外部链接,并在原始页面上等待确认弹出窗口,让他们在返回时进行确认?
$(document).ready(function(){
$('.goal-completed').click(function(){
var ss = confirm('Please confirm that you performed the action');
if(ss){
var id, data, url = '/dashboard/notify/admin/'
id = $(this).attr('task-id');
data = {id: id};
$.post(url, data, function(r){
if(r.response == 'OK'){
alert('We will confirm and give you the points that you earned!');
}
});
}
})
});
<section class="dashboard-section">
<div class="container-fluid">
<div class="row">
<h1 class="blue register-title">Link and email test</h1>
</div>
<div class="row">
<div class="col-lg-6">
<a href="http://www.google.com" target="_blank" class="goal-completed" task-id="6" task-name="Test">Link & Email</a>
</div>
</div>
</div>
</section>
您可以执行以下操作:
- 用户点击按钮
- 打开的新窗口带有其他URL
- 弹出窗口打开,用户可以确认。这个弹出窗口的外观在不同的浏览器中会有所不同。例如,在Safari中,在用户返回原始窗口/选项卡之前,弹出窗口不会出现,但在Chrome中,它会立即出现
您可以在此处测试此片段:http://jworldhosting.com/Uploads/StackOverflow/windowOpenAlert.html因为StackOverflow片段似乎阻止了警报和url更改的演示
function loadAlert() {
window.open("http://www.google.com", '_blank');
var ss = confirm('Please confirm that you performed the action');
if (ss) {
var id, data, url = '/dashboard/notify/admin/'
id = $(this).attr('task-id');
data = {
id: id
};
$.post(url, data, function(r) {
if (r.response == 'OK') {
alert('We will confirm and give you the points that you earned!');
}
});
}
}
<section class="dashboard-section">
<div class="container-fluid">
<div class="row">
<h1 class="blue register-title">Link and email test</h1>
</div>
<div class="row">
<div class="col-lg-6">
<a href="javascript:loadAlert();" class="goal-completed" id="goal-completed" task-id="6" task-name="Test">Link & Email</a>
</div>
</div>
</div>
</section>
我想提供最终解决方案的更新。我最终使用HTML创建了一个隐藏模式的弹出窗口,并在单击链接按钮时删除了隐藏的类。现在一切都按需要进行。
$(document).ready(function() {
$('.goal-completed').click(function() {
var id, data, url = '/dashboard/notify/admin/'
id = $(this).attr('task-id');
data = {
id: id
};
$.post(url, data, function(r) {
if (r.response == 'OK') {
alert('We will confirm and give you the points that you earned!');
}
});
})
$('.goal-pop').click(function(event) {
$("#modal").removeClass('hidden');
$("#goal-confirm").removeClass('hidden');
$("#close").removeClass('hidden');
$("#overlay").removeClass('hidden');
});
});
#overlay {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #000;
opacity: 0.5;
}
#modal {
background: rgba(0, 0, 0, 0.2);
border-radius: 14px;
padding: 8px;
position: fixed;
top: 50%;
left: 50%;
margin-top: -50px;
margin-left: -100px;
}
#goal-confirm {
border-radius: 8px;
background: #fff;
padding: 20px;
}
#close {
position: absolute;
width: 24px;
height: 27px;
display: block;
top: 9px;
right: -1px;
}
.hidden {
display: none;
}
.btn-yesno {
position: relative;
float: left;
width: 45%;
padding: 5px;
margin-top: 5px;
margin-bottom: 12px;
margin-left: 2%;
margin-right: 2%;
text-align: center;
font-size: 16px;
border: 1px solid;
border-color: rgba(136, 136, 136, 0.2);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.btn-goals {
position: relative;
float: left;
width: 85%;
padding: 10px;
margin-bottom: 12px;
margin-right: 1%;
text-align: center;
font-size: 16px;
border: 1px solid;
border-color: rgba(136, 136, 136, 0.2);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.btn-action {
color: #fff;
background-color: #F5A623;
<section class="dashboard-section">
<div class="container-fluid">
<div class="row">
<div class="col-lg-6">
<a href="www.google.com" target="_blank" class="btn btn-block btn-goals goal-pop">Complete Task</a>
</div>
</div>
</div>
<div id='overlay' class='hidden'></div>
<div id='modal' class='hidden'>
<div id='goal-confirm' class='hidden'>
Did you complete the task?</strong>
<div class="row">
<div class="col-lg-12">
<a href="/dashboard" class="goal-completed btn btn-block btn-yesno btn-yes">Yes</a>
<a href="/dashboard" class="btn btn-block btn-yesno btn-no">No</a>
</div>
</div>
</div>
<a href='#' id='close' class='hidden'>X</a>
</div>
</section>
{% endblock %} {% block javascript %}
<script src="{{ STATIC_URL }}js/jquery.csrf.js"></script>
<script src="{{ STATIC_URL }}js/goal.js"></script>
{% endblock %}
相关文章:
- 是否可以将JXBrowser显示的JS确认对话框的结果返回到调用它的JS部分
- 在离开Aurelia.js上的页面之前,我如何要求用户进行确认
- 按钮链接加载后JS确认弹出
- JS在更改事件中循环在JS中确认
- 如何在提交时向Happy.js添加确认消息
- 为什么JS confirm()获胜't当我在确认对话框中点击“取消”时,取消提交操作
- 为什么这个JS确认窗口没有在表单提交时启动
- 正在寻找特定的JS方法来确认单选按钮的选择
- 在幻像.js中确认警报窗口
- 流星.js单例确认框
- 如果用户不接受JS确认消息,如何检查上一个选定的单选按钮
- 警报 JS 确认无法使用按钮链接
- Angular JS应用设备后退按钮必须具有确认对话框
- 分机.js确认方法添加新行字符
- 在离开站点跨浏览器 (JS) 之前确认消息
- 警报.js - 导轨自定义确认对话框
- 确认弹出并将php值传递给js,输入图像作为提交
- 如何确认img文件的副本,转换完成,使用node.js
- "消息发送”;PHP和JS的确认弹出窗口
- PayPal确认,然后返回一个字符串HTML(js或任何其他..)