如果窗口具有相同的 url(并且仍然从上一个窗口打开),如何恢复窗口而不是打开一个新窗口?

发布于 2025-01-03 03:34:35 字数 1389 浏览 3 评论 0原文

我使用下面的类来弹出一个特定的窗口,但我想问如何使用同一个类,如果用户单击一个按钮并弹出具有特定 URL 的窗口,然后使用相同的 URL 再次单击该按钮,我不这样做想要打开一个新窗口,如果它仍然打开,则只是同一个窗口。

public static void Redirect(string url, string target, string windowFeatures)
        {
            HttpContext context = HttpContext.Current;
            if ((String.IsNullOrEmpty(target) ||

                target.Equals("_self", StringComparison.OrdinalIgnoreCase)) &&

                String.IsNullOrEmpty(windowFeatures))
            {
                context.Response.Redirect(url);
            }
            else
            {
                Page page = (Page)context.Handler;

                if (page == null)
                {
                    throw new InvalidOperationException("Cannot redirect to new window outside Page context.");
                }

                url = page.ResolveClientUrl(url);
                string script;
                if (!String.IsNullOrEmpty(windowFeatures))
                {
                    script = @"window.open(""{0}"", ""{1}"", ""{2}"");";
                }
                else
                {
                    script = @"window.open(""{0}"", ""{1}"");";
                }
                script = String.Format(script, url, target, windowFeatures);
                ScriptManager.RegisterStartupScript(page, typeof(Page), "Redirect", script, true);
            }
        }

I use the following class to pop up a specific window , but i wanna to ask how to use the same class ,if the user clicks a button and popup window with specific URL then click the button again with the same URL , i don't want to open a new window,just the same window if it still opened.

public static void Redirect(string url, string target, string windowFeatures)
        {
            HttpContext context = HttpContext.Current;
            if ((String.IsNullOrEmpty(target) ||

                target.Equals("_self", StringComparison.OrdinalIgnoreCase)) &&

                String.IsNullOrEmpty(windowFeatures))
            {
                context.Response.Redirect(url);
            }
            else
            {
                Page page = (Page)context.Handler;

                if (page == null)
                {
                    throw new InvalidOperationException("Cannot redirect to new window outside Page context.");
                }

                url = page.ResolveClientUrl(url);
                string script;
                if (!String.IsNullOrEmpty(windowFeatures))
                {
                    script = @"window.open(""{0}"", ""{1}"", ""{2}"");";
                }
                else
                {
                    script = @"window.open(""{0}"", ""{1}"");";
                }
                script = String.Format(script, url, target, windowFeatures);
                ScriptManager.RegisterStartupScript(page, typeof(Page), "Redirect", script, true);
            }
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

药祭#氼 2025-01-10 03:34:35

window.open 方法的第二个参数是目标窗口的名称。如果您对两个调用使用相同的值,则第二个调用会将其页面加载到先前打开的窗口中。

window.open('./a.html', 'popup', ...);
window.open('./b.html', 'popup', ...);

只会有一个窗口加载页面 b.html

The second arguments of the window.open method is the name of the target window. If you use the same value for both calls, the second call will load its page into the previously opened window.

window.open('./a.html', 'popup', ...);
window.open('./b.html', 'popup', ...);

There will be only one window with the page b.html loaded.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文