简体   繁体   English

如何禁用浏览器回发警告对话框

[英]How to disable browser postback warning dialog

I have an asp.net application that runs exclusively on IE7 (internal web site). 我有一个专门在IE7(内部网站)上运行的asp.net应用程序。

When a user needs to enter data, I pop up a child window with a form. 当用户需要输入数据时,我会弹出一个带有窗体的子窗口。 When the form closes, it calls javascript:window.opener.location.reload(true) so that the new data will display on the main page. 表单关闭时,它将调用javascript:window.opener.location.reload(true),以便新数据将显示在主页上。

The problem is that the browser complains that it must repost the page. 问题是浏览器抱怨它必须重新发布页面。 Is there any way to turn this feature off? 有什么办法可以关闭此功能?

No, but there is a solution. 不,但是有解决方案。 Its generally considered good design to use a 302 redirect immediately after someone posts data to a page. 通常认为,在有人将数据发布到页面后立即使用302重定向的良好设计。 This prevents that popup from ever occuring. 这样可以防止该弹出窗口发生。 Allow me to elaborate. 请允许我详细说明。

1) The user fills in a form and submits data via POST. 1)用户填写表格并通过POST提交数据。

2) The backend receives the data and acts upon it. 2)后端接收数据并对其进行操作。

3) Instead of returning the content to the user, the backend issues a 302 redirect as soon as its done processing the page (possibly redirecting the user back to the exact same url, if need be) 3)后端没有将内容返回给用户,而是在处理完页面后立即发出302重定向(如果需要,可以将用户重定向回完全相同的url)

4) The page that the user will see is the page you told their browser to redirect to. 4)用户将看到的页面是您告诉其浏览器重定向到的页面。 They will load up the redirected page with a standard GET request. 他们将使用标准的GET请求加载重定向页面。 If they try to refresh the page, it will not repost the data. 如果他们尝试刷新页面,它将不会重新发布数据。 Problem solved. 问题解决了。

This is a problem with the usual "postback" way of ASP.NET. 这是ASP.NET通常的“回发”方式的问题。 If you need to reload a page without this warning, this page must come from a GET, not a POST. 如果您需要在没有此警告的情况下重新加载页面,则该页面必须来自GET,而不是POST。 You could do a Response.Redirect("...") yourself. 您可以自己执行Response.Redirect(“ ...”)。 But this will destroy the use of viewstate. 但这将破坏viewstate的使用。

asp.net mvc fixes this issue, not an ie7 only problem but a security feature of most browsers. asp.net mvc可以解决此问题,而不是仅解决ie7的问题,而是大多数浏览器的安全功能。 No fix that I know of except you could just update the content in the main form with js rather than reloading the whole page 除了您可以用js更新主表单中的内容,而不是重新加载整个页面外,我没有其他解决方法

If you move from page1 to page2, and want to disable the browser from going back to page 1,then add the following at the top of page1. 如果您从第1页移到第2页,并且想禁止浏览器返回第1页,则在第1页的顶部添加以下内容。

<script>
if(window.history.forward(1) != null)
                 window.history.forward(1);
</script>

I do not believe that there is a way to do that. 我不认为有办法做到这一点。 Instead, why not direct the parent window to a page without a reload. 相反,为什么不将父窗口定向到没有重新加载的页面。

javascript:window.opener.location='your url' javascript:window.opener.location ='您的网址'

It's because the page in window.opener comes from a POST Request Maybe you can use javascript:window.opener.location = window.opener.location; 这是因为window.opener中的页面来自POST请求也许您可以使用javascript:window.opener.location = window.opener.location; to do just a GET request if the data can be fetched without a POST. 如果可以在没有POST的情况下获取数据,则仅执行GET请求。

AFAIK, not via your scripts. AFAIK,而不是通过您的脚本。

You might try: 您可以尝试:

window.opener.location = '#';

It should circumvent the browser reposting. 它应该避免浏览器重新发布。 And, you can adjust the hash name as needed. 并且,您可以根据需要调整哈希名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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