简体   繁体   中英

window.confirm take the cancel button out

How do I take the cancel Button from the window.confirm?? Is there a way to taking it out and only the OK button will show up?

If you don't want a cancel button, you might as well just use alert() :

alert('This operation is not possible');

In beautiful ascii art it looks like this:

+-----------------------------------+
|                                   |
|  This operation is not possible   |
|                                   |
|            +--------+             |
|            |   OK   |             |
|            +--------+             |
+-----------------------------------+

When either OK is clicked or the dialog is dismissed, the next statement in your code will be executed.

If the next statement should be conditional, you'd have to stick with confirm() unfortunately.

window.alert is what you want.

Or simply alert , just like window.confirm can be confirm (unless you hide those with variables with those names.

You can simply use the alert . Following is an example:

HTML

<button id="test"> Go To Another Page</button>
<br><br>
<iframe src='http://www.example.com' height="400px" width="100%" id="page"></iframe>

jquery

$(document).ready(function(){
    $('#test').click(function(){
        var page = $('iframe');
        alert("You'll be redirected to a new page now");
        page.attr('src', 'http://www.monkeyman.com'); // This line is executed once you hit ok on the alert.
    });
});

Here is a working JSFiddle . I had to use an iframe because of jsfiddle. In your scenario you may want to remove the iframe thing and simply change:

page.attr('src', 'http://www.monkeyman.com');

to

window.location('http://www.monkeyman.com');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM