0

Possible Duplicate:
Javascript close alert box

Hi I would like to ask if it's possible to have an id #myID which when clicked will pop-up an alert box and after a few seconds WITHOUT clicking the OK button on alert it will redirect to another page? Here's my code:

 $('#myID).click(function(){
     alert('Ta-da! Do not click the OK button just wait for a few seconds before it redirects to other page.');  
 })

Somehow that's what I want. Is that possible?

Community
  • 1
  • 1
Tsukimoto Mitsumasa
  • 541
  • 4
  • 19
  • 42
  • 3
    Only with a custom dialog, not with the built-in `alert`. – Felix Kling Aug 27 '12 at 19:53
  • @FelixKling Thanks, but how would I do that on the custom dialog? – Tsukimoto Mitsumasa Aug 27 '12 at 19:56
  • 1
    @CHi: HTML + CSS + JS `
    Custom Message
    ` AND `#my-dialog { /*CSS Properties to center and zindex*/}` AND JS to add dialog to DOM, add timeout, and maybe put a nice overlay on things.
    – Francis Yaconiello Aug 27 '12 at 20:01
  • Or.. heres an idea.. in most browsers an alert in a sense halts the script til an action is made. But even then, with this logic Im thinkin.. you could always just setTimeout and give it a few seconds.. but thats only if you want to use the default alert, there is also "yes" "no" alert dialogs and other things to consider. – chris Aug 27 '12 at 20:12
  • @chris that doesn't work. alert stops execution of a script. the timer essentially stops until the script is resumed. – Francis Yaconiello Aug 27 '12 at 20:14

1 Answers1

2

Use a custom dialog: A quick one if you dont already ahave any plugins like jQuery ui in your site.

var dialog = $('<div id="dialog"> You are going away, Bye Bye </div>');
dialog.css({
    position:'fixed',
    top: 100,
    left: '50%',
    width: '200px',
    'margin-left': '-100px',
    'z-index' : 99999,
    border: '1px solid #444444',
    'background-color' : '#FFFFF'
    });
$('body').append(dialog);

http://jsfiddle.net/R7qSR/

sabithpocker
  • 15,274
  • 1
  • 42
  • 75