admin管理员组

文章数量:1313809

I want to execute some code when an alert is accept by the user, I know about this:

if(confirm("Go to the next step"))  
  {
    document.write("accepted");
  }  
else{  
   document.write("rejected");  
}  

the point is I want the box to have only one button like the normal alert, and by clicking it I can execute something.

I want to execute some code when an alert is accept by the user, I know about this:

if(confirm("Go to the next step"))  
  {
    document.write("accepted");
  }  
else{  
   document.write("rejected");  
}  

the point is I want the box to have only one button like the normal alert, and by clicking it I can execute something.

Share Improve this question asked May 7, 2012 at 5:52 Ahmed WaheedAhmed Waheed 1,2916 gold badges21 silver badges39 bronze badges 3
  • simple if you want only one button and forcefully ask the user to accept the alert then use alert box rather than confirm. – Murtaza Commented May 7, 2012 at 5:55
  • What do mean by displaying only one button and right the code to check user has accepted or not. He will have to forcefully accept it, thats the only option for user. – Murtaza Commented May 7, 2012 at 5:56
  • actually you are already executing something ... document.write(...) is your action – user57508 Commented May 7, 2012 at 5:57
Add a ment  | 

3 Answers 3

Reset to default 8

You can use the alert mand in javascript: http://www.w3schools./js/js_popup.asp

I believe any line of javascript code that is placed after the alert line is executed after the alert window closes.

Whatever statement you put after alert will be executed when user clicks on okay.
Fiddle
And when you say alert user don't have any other choice other than clicking on okay.

  • alert() - One button (OK) Try a demo: http://jsfiddle/DerekL/3R3yV/
  • confirm() - Two buttons (OK, cancel)
  • prompt() - Two buttons + one input field (OK, cancel)

For other buttons, you might want to try out jQuery UI.

      jQuery User Interface does let developers to create custom dialogs.

本文标签: javascriptDo something upon accepting an alertStack Overflow