0
我希望用户在离开网页时收到警告。我还希望用户在按某个按钮提交内容时获得不同的警报。在你离开网页时,一切正常,但当你按下提交时,你会看到两条警告消息。我如何得到这个只显示一个警报?如何在离开页面时警告用户,而不是在按下按钮时警告用户?
<asp:Button Style="display: inline-block; margin-left: 120px; margin-top: 10px;" ID="SendEmail" runat="server" CssClass="btn-flat success" Text="Send email" OnClick="btnUpdate_click" Visible="true" Enabled="True" OnSubmit="window.onbeforeunload = false;" OnClientClick="if (!confirm('Are you sure you want to send this email?')) return false;"/>
<script>
window.onbeforeunload = function() {
return "Do you want to leave this page?";
}
我用window.onbeforeunload离职的网页,当你按下按钮提交了的OnClientClick调用。我没有Javascript的经验,所以我不知道我在做什么。
只需创建一个标志,以保持按钮是否被点击或不和,并显示像'如果(标志){警报的消息(“你想离开这个页面?“); }' –