Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/440.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用X按钮关闭模式时的窗口返回值_Javascript_Html_Internet Explorer - Fatal编程技术网

Javascript 使用X按钮关闭模式时的窗口返回值

Javascript 使用X按钮关闭模式时的窗口返回值,javascript,html,internet-explorer,Javascript,Html,Internet Explorer,我正在开发一个web应用程序,我们的客户通过以下方式调用该应用程序: var result = window.showModalDialog('http://example.com/myapp','My webapp', 'dialogtop=0;dialogleft=0;dialogwidth:' + (window.screen.width - 200) + ';dialogheight:' + (window.screen.height - 200) + ';status=no;resiz

我正在开发一个web应用程序,我们的客户通过以下方式调用该应用程序:

var result = window.showModalDialog('http://example.com/myapp','My webapp', 'dialogtop=0;dialogleft=0;dialogwidth:' + (window.screen.width - 200) + ';dialogheight:' + (window.screen.height - 200) + ';status=no;resizable=yes;scroll=yes;maximize:yes;minimize:no;' );
当他们关闭这个模式对话框时,他们捕获了我们返回的内容

我们在window.returnValue中加载响应,这样他们就可以在“result”变量中找到它,但是如果他们用X按钮关闭窗口,他们就永远不会得到我们的响应,尽管我们已经设置了它。如果他们通过点击我们的“接受”按钮来关闭我们的窗口,他们就会得到响应

如果我试图捕获卸载事件,并且再次设置window.returnValue,他们也不会得到它

为什么会发生这种情况?我如何确保他们即使按X键也能得到返回值

我无法改变他们对我们的web应用程序的调用方式,我知道这很糟糕,因为这是一种愚蠢的做事方式


他们专门使用Internet Explorer,并在IE 5模式下运行…

如果可能,您可以尝试使用

这样,您可以尝试向用户显示提示,并告知他们如果继续使用此方法,他们可能会丢失在此页面上所做的更改。然后您可以用正确的步骤指导用户

例如:

window.onbeforeunload = confirmExit;
function confirmExit()
{
    return "You have attempted to leave this page.  If you have made any changes to the fields without clicking the Accept button, your changes will be lost.  Are you sure you want to exit this page?";
}

您可以分享
showModalDialog
函数的内容吗?showModalDialog不是我开发的函数:因为关闭模式是异步的,所以当关闭模式时,您需要使用承诺和回调函数来执行事件。对于精确的代码,您只能使用停止执行JavaScript的默认警报/确认/提示函数,其他所有函数都不会阻止执行。