简体   繁体   English

如何使用Process.Start()在当前浏览器选项卡上打开HTML文件

[英]How to open a html file on current browser tab using Process.Start()

I have the code below 我有下面的代码

System.Diagnostics.Process.Start("ClosePopup.html");

ClosePopup.html is the html file below ClosePopup.html是下面的html文件

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
</head>
<body onload="window.close()">
</body>
</html>

I am trying to open this HTML file on the current tab and it will close itself since I cannot close a tab opened by a user, however, this code opens this HTML file in a new tab and instantly closing it so the tab I am trying to close remains open. 我正在尝试在当前标签页上打开此HTML文件,由于无法关闭用户打开的标签页,该文件将自行关闭,但是,此代码在新标签页中打开了此HTML文件并立即将其关闭,因此我正在尝试使用此标签页关闭仍然保持打开状态。 How can I change the target tab of the Process.Start() function? 如何更改Process.Start()函数的目标选项卡?

In short, you can't do what you're trying to do. 简而言之,您无法做您想做的事情。 Just so happens you are accessing the site on the server itself, so when you start that html process - it's opening on the server. 碰巧的是,您正在访问服务器本身上的站点,因此,当您启动该html进程时-它正在服务器上打开。 Others accessing your site would never see that. 其他访问您网站的人永远不会看到。

Given the requirements you added some clarity on in the comments I'd suggest a client-side approach like the following: 鉴于您的要求,您在注释中增加了一些清晰度,我建议采用如下所示的客户端方法:

$("#theForm").ajaxSubmit({url: '[some action]',
                          type: 'post',
                          success: function() { window.close(); }})

This has the added benefit of you also being able to only close the window if the response was a successful one. 这还有一个额外的好处,即您还可以仅在响应成功后才关闭窗口。 Currently, with the way you're trying to do it, even a failed request would result in a closed tab. 当前,以您尝试执行此操作的方式,即使失败的请求也将导致选项卡关闭。

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

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