Вы можете использовать button
вместо a
тега и применить css
к кнопке, чтобы она выглядела как a
тег. Здесь, в приведенном ниже коде всякий раз, когда вы нажимаете button
, всплывающее окно открывается, если нажать «да», то страница перенаправляется напрямую, иначе страница останется на той же странице.
function confirmation(button) {
//getting href value
var href = button.getAttribute("href");
console.log(href);
var result = confirm("vous êtes sûr ?");
if (result) {
//if click yes redirect
window.location.href = href;
} else {
return false;
}
}
.supprimer {
background-color: transparent;
text-decoration: underline;
border: none;
color: blue;
cursor: pointer;
}
supprimer:focus {
outline: none;
}
<table>
<thead>
<tr>
<th>ID</th>
<th>Date RDV</th>
<th>Motif</th>
<th>ID Patient</th>
<th>Action</th>
</tr>
</thead>
<p:forEach items="${liste }" var="rdv">
<tbody>
<tr>
<td>${rdv.id_Rdv }</td>
<td>${rdv.date_Rdv }</td>
<td>${rdv.motif }</td>
<td>${rdv.id_P }</td>
<td>
<button class="supprimer" href="${pageContext.request.contextPath}/RDVController?action=supprimer&Id_Rdv=${rdv.id_Rdv }" onclick="confirmation(this)"> Supprimer</button>
</td>
</tr>
</tbody>
</p:forEach>
</table>