Reputation: 285
I need to close the window after alertbox, I used the codes which was asked in Stack Question But my alert box is inside a php code, I am getting the alert box but once i close it the window is not getting closed, I am new to php . The codes are below, Please help me out guys
<?php
$serial_get = trim(str_replace("(","",str_replace(")","",GetVolumeLabel("d"))));
if ($serial_get == '1233-2AZ2'){
}
else{
echo '<script language="javascript">
window.alert("This is not a Licensed Software. Please contact IT Solutions.");
window.close()
</script>'; }?>
Upvotes: 5
Views: 1468
Reputation: 5454
Some browsers won't respect the command unless it is user-initiated. But... Here's a workaround that may work for you. try this instead of close
:
open(location, '_self').close();
Or maybe fool the browser into thinking it was user initiated. This may or may not work; haven't tested. I'm just throwing spaghetti at the wall...
var btn = document.createElement('button');
document.body.appendChild(btn);
btn.addEventListener('click', function() {
open(location, '_self').close();
}, false);
btn.dispatchEvent(new Event('click'));
Upvotes: 0
Reputation: 1283
You need window.open(...)
to be able to window.close()
. You are using window.alert()
.
See Best Practice in the link https://developer.mozilla.org/en-US/docs/Web/API/Window.open
Upvotes: 1