防止网页对话框产生新的浏览器窗口?

发布于 2025-01-01 00:39:29 字数 1504 浏览 1 评论 0原文

我有一个打开的网页对话框。从那里,我想做的是,当用户单击链接时,使用修改后的查询字符串参数刷新对话框的内容。我遇到的问题是,不是使用新参数刷新同一网页,而是弹出一个新的浏览器窗口。

这是用于打开对话框的页面:

<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
    function ShowPopup() {
        var popWinFeatures = "dialogWidth: 800px;dialogHeight:600px;center:yes;status:no;scroll:no;resizable:yes;help:no";

        window.showModalDialog("webPageDialog.html","PopUpWin",popWinFeatures);

    }
</script>
</head>
<body>
    <a href="#" id="openWebPageDialog" onclick="ShowPopup()">Click For Modal</a>
</body>
</html>

这是网页对话框中的代码,尝试使用更改后的查询字符串参数刷新网页:

<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="scripts/jquery-1.6.4.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function(){
        var queryString = "?ab=123";
        var newURL = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname;

        $('#testLink').attr('href', newURL+queryString);
    });

</script>
</head>
<body>
<a href="#" onclick="" id="testLink" target="_self">Please Click Me</a>
</body>
</html>

我还尝试使用 window.open 以及设置window.location。我也尝试过设置 window.location.href 但结果是相同的。

新的浏览器窗口显示的内容正是我所期望的。只是不在同一个窗口中。

想法?

I have an open web page dialog. From there, what I'd like to do is when the user clicks on a link, refresh the contents of the dialog with modified query string parameters. The problem I am running into is that rather than refresh the same web page with new parameters, a new browser window pops up.

Here is the page used to open the dialog:

<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
    function ShowPopup() {
        var popWinFeatures = "dialogWidth: 800px;dialogHeight:600px;center:yes;status:no;scroll:no;resizable:yes;help:no";

        window.showModalDialog("webPageDialog.html","PopUpWin",popWinFeatures);

    }
</script>
</head>
<body>
    <a href="#" id="openWebPageDialog" onclick="ShowPopup()">Click For Modal</a>
</body>
</html>

and this is the code within the webpage dialog that attempts to refresh the webpage with changed query string parameters:

<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="scripts/jquery-1.6.4.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function(){
        var queryString = "?ab=123";
        var newURL = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname;

        $('#testLink').attr('href', newURL+queryString);
    });

</script>
</head>
<body>
<a href="#" onclick="" id="testLink" target="_self">Please Click Me</a>
</body>
</html>

I've also tried using window.open as well as setting window.location. And I've also tried setting window.location.href but the result was the same.

the new browser window displays exactly what I expect. It's just not in the same window.

Thoughts?

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

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

发布评论

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

评论(1

昔日梦未散 2025-01-08 00:39:29

自从发布这个问题以来,我想出了两种可能的解决方案。如果有人跟踪我并想知道我最后做了什么,就给你!

第一个只是使弹出窗口成为非模态的。删除模态部分使我的行为完全符合我的预期。然而,这在我的情况下不起作用,但出于不同的原因...似乎会话 cookie 没有被继承,在这个 Web 应用程序中,这会导致在显示正确的页面之前显示登录页面。这让我觉得很奇怪,但我没有时间去调查为什么会发生这种情况。

其次(这是我最终采用的解决方案)是使用 iframe,并在 iframe 中显示我需要的内容。绝对不是我最喜欢的,但它确实有效!

Since posting this question, I came up with two possible solutions. In case anyone comes after me and wants to know what I ended up doing, here you go!

The first was just to make the popup non-modal. Removing the modal piece gave me the behavior exactly like I expected it. This didn't work in my situation however for a different reason... It seems that the session cookie was not carried over which in this web app, would cause the log-in page to be displayed before then displaying the correct page. This struck me as odd, but ran out of time to investigate why that was happening.

Second (and this is the solution i ended up going with) was to use an iframe, and display what i needed within the iframe. Definitely not my favorite, but it works!

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