2013-06-28 36 views
0

我希望用户通过jQuery UI对话框确认当单击mailto链接时他或她接受或拒绝某些条款。当我使用下面的代码时,对话框会短暂出现,但随着页面被重定向到默认的电子邮件程序,会自动关闭。如何强制jQuery对话框等待响应

的jQuery:

$(function() { 
    .html('Do you accept these terms?') 
    .dialog({ 
     autoOpen: false, 
     title: 'Disclaimer', 
     resizable: false, 
     width: 500, 
     modal: true, 
     buttons:    
      { 
    "Accept": function() { 
     $(this).dialog("close");}, 
    "Reject": function() { 
     $(this).dialog("close"); } 
} 
}); 

$('.email-address').click(function() { 
    $dialog.dialog('open'); 

}); 
}); 

HTML:

<a class="email-address" href="mailto:'[email protected]">[email protected]</a> 

上要求对话框之前响应的最佳方法有什么建议可以关闭?

回答

1

我会从html中删除href =“mailto”,将其设置为#并从函数内部运行mailto。

HTML:

<a class="email-address" href="#">[email protected]</a> 

JS:

$(function() { 
    .html('Do you accept these terms?') 
    .dialog({ 
    autoOpen: false, 
    title: 'Disclaimer', 
    resizable: false, 
    width: 500, 
    modal: true, 
    buttons:{ 
     "Accept": function() { 
     $(this).dialog("close"); 
     window.location.href = "mailto:[email protected]"; 
     }, 
     "Reject": function() { 
     $(this).dialog("close"); } 
     } 
    }); 

    $('.email-address').click(function() { 
    $dialog.dialog('open'); 

    }); 
}); 
+0

工作正常。谢谢! – Ken

1

这是因为你点击链接的默认操作,你需要阻止链接的默认操作和接受你需要将用户重定向到页面