防止网页对话框产生新的浏览器窗口?
我有一个打开的网页对话框。从那里,我想做的是,当用户单击链接时,使用修改后的查询字符串参数刷新对话框的内容。我遇到的问题是,不是使用新参数刷新同一网页,而是弹出一个新的浏览器窗口。
这是用于打开对话框的页面:
<!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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
自从发布这个问题以来,我想出了两种可能的解决方案。如果有人跟踪我并想知道我最后做了什么,就给你!
第一个只是使弹出窗口成为非模态的。删除模态部分使我的行为完全符合我的预期。然而,这在我的情况下不起作用,但出于不同的原因...似乎会话 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!