Can jQuery dialog be used in place of a javascript confirm?
I can not figure out how to replace a javascript confirm with a jQuery dialog. I can attach it to my links, but when the user clicks Yes, I don't know how to find the link that initiated the action and how to continue the click event so it works universally for href and onclick. Thoughts?
- <html>
- <head>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
- <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.4/jquery-ui.min.js"></script>
- <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/base/jquery-ui.css" type="text/css" media="all" />
- </head>
- <body>
- <a href="http://www.google.com">google</a><br />
- <a href="#" onclick="document.location.href='http://www.yahoo.com';return false;">yahoo</a><br />
- <a href="#" onclick="if( confirm('do it?') ) document.location.href='http://www.dogpile.com';return false;">dogpile</a><br />
- <div id="warning" style="display: none;">Do the link?</div>
- <script>
- $().ready(function(){
- $('#warning').dialog({
- modal: true,
- autoOpen: false,
- width: 500,
- buttons: {
- 'Yes': function() { $(this).dialog('close') },
- 'No': function() { $(this).dialog('close') }
- }
- });
- });
- $('a').click(function(event){
- $('#warning').dialog('open');
- event.preventDefault();
- });
- </script>
- </body>
- </html>