我正在做一个项目,我遇到了window.open的问题。问题是window.open在我的架构中不起作用。我需要一个帮助,
swal({
title: "Submit Data ?",
text: "Process only if you are sure",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, Submit!",
cancelButtonText: "No, Cancel!",
closeOnConfirm: false,
closeOnCancel: false
},
function(isConfirm){
if (isConfirm) {
insertData();
swal("SUCCESS", "Data Has Been Submitted", "success");
window.open("http://188.109.156.21/execution.php?str=james");
} else {
swal("CANCELLED", "", "error");
}
});
function insertData(){
$.ajax({
type: 'POST',
url: "../../../html/main/divpages/submit_data.php",
data: sentReq,
dataType: 'JSON',
success: function (response, textStatus, jqXHR) {
if (response.indexOf("GAGAL") == -1) {
window.location.href = "main.php";
} else {
alert("GAGAL INSERT");
}
}
});
}
所以我可以毫无问题地执行insertData()。但问题在于在swal()内执行windows.open时。我没有看到任何窗口弹出窗口正在打开。
答案 0 :(得分:1)
这是浏览器使用的弹出式阻止逻辑。您必须直接在onClick事件上附加window.open。
使用类似的东西:
var checkSuccess = false;
$('#button').on("click", function(){
$.ajax({
type: 'POST',
url: "your url",
async:false,
success: function(){
checkSuccess = true;
//YOUR LOGIC
}
});
if(checkSuccess){
window.open("http://188.109.156.21/execution.php?str=james");
}
})