1

My Code :.....

<html>
<head>
<script>
function demo()
{
    var win=window.open("demo.html",'_blank');
    alert('Requested Page Loaded...');
    win.focus();
}
</script>
</head>
<body>
<input type="button" value="demo" onClick="demo()"></input>
</body>
</html>

I want to close the alert event dynamically using JavaScript event. When alert is come in seen and it will close automatically using JavaScript event fire and close it..

4
  • 1
    You cannot close an alert dialog programmatically. Commented Dec 2, 2013 at 4:31
  • Its depend if cannot close then it will fire event like ok button press automatically. Commented Dec 2, 2013 at 4:34
  • 1
    alert dialogs are blocking. Even if it was possible to create such an event, you could not trigger it because no code can be executed while the dialog is shown. Commented Dec 2, 2013 at 4:35
  • Write @FelixKling it is not possible to fire any event when dialog is appear. But Can we Fire Bubble Event or Combine Event in Javascript like KeyboardEvent + MouseEvent both at the same time? Or Another Option is we can Loose Focus of Opening in New Tab and Set Focus of Current Tab. e.g. window.focus(); and window.blur(); Commented Dec 2, 2013 at 4:58

1 Answer 1

1

You could create a pseudo-alert. You can make it a modal if it is closed by a programmed event (instead of screen-triggered).

HERE is a fiddle. (click on two colors to open and close alert.

HTML

<div class='testdiv'></div>
<div class='testdiv3'></div>
<div id='dialogtest' class='testdiv2'>Alert!</div>

CSS

.testdiv {
    width: 100px;
    height: 100px;
    margin: 0px auto;
    background-color: red;
}
.testdiv3 {
    width: 100px;
    height: 100px;
    margin: 0px auto;
    background-color: green;
}

.testdiv2 {
    background-color: green;
    width: 50px;
    height: 50px;
    font-size: 15px;
}
.ui-dialog-titlebar {
    display: none;
}

JS

$( ".testdiv2" ).dialog({
                       autoOpen: false,
                          modal: false,
                         height: 50,
                          width: 'auto',
                       position: { my: "right middle",
                                   at: "left middle",
                                  of : ".testdiv" } 
                           });

$('.testdiv').click(function(){
  $('.testdiv2').dialog('open');
});
$('.testdiv3').click(function(){
  $('.testdiv2').dialog('close');
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.