这是我的代码,我想点击打印取消然后我的脚本不执行我会点击确定然后这个代码将运行。请给我积极的反馈。
(function() {
var afterPrint = function() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
console.log('Responce',this.responseText);
//document.getElementById("demo").innerHTML = this.responseText;
}
};
xhttp.open("POST", "<?php echo site_url('AppsCtr/updatePrintLog');?>", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("COMP_CODE=<?php echo $session_company_name;?>&UIL_DOC_NO=<?php echo $head[0]['OPH_TXN_CODE'].'-'.$head[0]['OPH_TXN_NO'];?>&UIL_SYS_ID=<?php echo $head[0]['OPH_SYS_ID'];?>&ACTION=Print&DETAILS=");
};
// supported by Chrome 9+ and Safari 5.1+
if (window.matchMedia) {
var mediaQueryList = window.matchMedia('print');
mediaQueryList.addListener(function(mql) {
if (mql.matches) {
beforePrint();
} else {
afterPrint();
}
});
}
// supported by IE 5+ and FireFox 6+
window.onafterprint = afterPrint;
}());
答案 0 :(得分:0)
好吧,你的问题格式有点糟糕,我觉得你想要点击确定的东西,点击取消时会有不同的东西,如果是这样,我建议你使用不同id的函数,例如:
<button id="ok" onclick="dosomething(this.id);"></button>
<button id="cancel" onclick="dosomething(this.id);"></button>
<script>
// this is the most important, for separate the diferent actions //
function dosomething(a) {
if (a === "ok") {
// your code of the popup ok //
}
if (a === "cancel") {
// the code of the popup cancel //
}
}
</script>