Aleksandar Djordjević Aleksandar Djordjević - 2 months ago 6
HTML Question

Javascript alert for deleting mysql data opens in new tab

I need to add JS alert for deleting certain records from mysql. Simple on... Sure you want to delete? Yes - leads to page to delete, No - does nothing. Problem is whenever i click on Yes it opens a new tab which i don't need (want all in current tab). Any solutions?

JS:

function confirmDelete(url) {
var aa = event.srcElement.id;
if (confirm("Sure to delete: "+ aa +"?")) {
window.open('/www/site/m_delete.php?id=' + aa +'');
} else {
return false;
}


}

HTML:

<a class="box_setting fa fa-ban" style="cursor:pointer;" id="'.$id.'" onClick="confirmDelete(\'/www/site/m_delete.php?id='.$id.'\')"></a>

Answer

For opening the page in same tab use this code:-

 window.open('/www/site/m_delete.php?id=' + aa +'', '_self'); // _self refers to window/tab that the code is currently running