的情況我想:如何使用javasciprt關閉瀏覽器選項卡(父窗口)
用戶按下一個按鈕,這個按鈕可以使一個警告框,用戶按下取消按鈕,動作關閉瀏覽器選項卡
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My page</title>
<style>
.bootbox-close-button.close{
display: none;
}
.btn-primary{
}
</style>
<!-- CSS dependencies -->
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
</head>
<body>
<p>
Content here. <a class="alert" href=#>Alert!</a>
</p>
<!-- JS dependencies -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<!-- bootbox code -->
<script src="js/bootbox.min.js"></script>
<script>
$(document).on("click", ".alert", function(e) {
bootbox.dialog({
message : "I am a custom dialog",
title : "Custom title",
buttons : {
ok : {
label : "OK",
className : "btn-primary"
},
cancel : {
label : "Cancel",
className : "btn-default",
callback : function() {
/*NEED TO HANDLE CLOSE IN THIS PLACE*/
window.parent.close();
}
}
}
});
});
</script>
</body>
</html>
我犯了這樣的,如果我貼近它說,
Scripts may close only the windows that were opened by it.
是否可以關閉父窗口?
您要關閉此頁面被打開的窗口或另一個窗口? –