在 PostBack 上重定向 UpdatePanel 内的父框架

发布于 2024-07-06 18:55:58 字数 340 浏览 8 评论 0原文

这是一个奇怪的问题,但我必须为我们的网站创建一个搜索框,该搜索框将在另一个网站上进行 iframe。 当用户单击搜索按钮时,需要将父框架重定向到我们的搜索结果页面。

目前我所做的是将搜索按钮设置为回发触发器,然后注册一个客户端脚本块来运行它:

if (window.parent) window.parent.location.href='<url>';

这是ok,但它看起来像是一个黑客和攻击。 这意味着如果用户在搜索后单击浏览器返回,则会将其重定向回搜索结果页面。

有更好的方法吗?

This is kind of a weird problem, but I have to create a search box for our site that will be iframed on another site. When the user clicks the search button, it needs to redirect the parent frame to our search results page.

At the moment what I've done is to make the search button a postback trigger then registering a client script block to run this:

if (window.parent) window.parent.location.href='<url>';

This is ok, but it seems like a hack & it means if the user clicks back on the browser after searching, it redirects them back to the search results page.

Is there a better way of doing this?

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

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

发布评论

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

评论(1

贱贱哒 2024-07-13 18:55:58

好吧,既然没有人回答,那我就试试吧。

首先,您是否以真实的方式测试您正在使用的代码? 我担心在现实应用程序中,您的 iframe 页面和父页面不会驻留在同一域中。 如果是这样,您的代码可能无法将父窗口定向到任何 URL。

如果允许您控制父框架的位置,那么您的代码对我来说看起来不错。 如果您不希望历史记录中出现新的URL,我相信您可以使用:

if (window.parent) { window.parent.location.replace("<url>"); }

参见示例: "Javascript 重定向方法之间的区别"

OK, since noone else has answered, I'll give this a go.

First off, are you testing the code you're using in a real-world way? I am concerned that in a real-world application that your iframed page and the parent page will not reside on the same domain. If so, there is not likely to be any way for your code to direct the parent window to any URL.

If you are allowed to control the parent frame's location, your code looks fine to me. If you don't want the new URL in the history, I believe that you can use:

if (window.parent) { window.parent.location.replace("<url>"); }

See for example: "The Difference Between Javascript Redirect Methods"

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