框架集导致 URL 在页面导航时不会更改。有办法解决这个问题吗?

发布于 2024-10-13 00:16:52 字数 453 浏览 8 评论 0原文

我们有一个网站,其中一个页面包含一个框架集(我们需要从另一个网站获取数据)。问题是,一旦您到达包含框架集的页面,即使单击其他链接,URL 也不再更改。它继续显示页面与框架集的链接。例如,带有框架集的页面的 URL 为:

http://www.ourwebsite.com/profile.php

通常,当您点击网站上的其他链接时,它会更改为该页面具有的任何 URL/页面名称。但在这里,一旦您登陆框架集页面,URL 就会以某种方式被屏蔽,只显示 http://www。 ourwebsite.com/profile.php 无论您在网站内走到哪里。

有办法解决这个问题吗?

We have a website and one of its pages contains a frameset (we need to get data from another website). The problem is, once you get to the page that contains the frameset, the URL no longer changes even if you click on other links. It keeps on showing the link of the page with the frameset. For instance the URL of the page with the frameset is:

http://www.ourwebsite.com/profile.php

Normally, when you click on other links on the website, it will change to whatever URL/page name that page has. But here, once you land on the frameset page, the URL is somehow masked to only show http://www.ourwebsite.com/profile.php wherever you go within the site.

Is there a way to get around this?

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

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

发布评论

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

评论(2

余生一个溪 2024-10-20 00:16:52

编辑:

如果您想显示来自另一个网站的框架,并且可以控制其他网站如何发出其 HTML,请按照下面我的原始答案中的说明操作,让框架发出带有 目标=“_top”

但是,如果您要构建一个无法控制的网站,那么使用框架可能不起作用。相反,您需要使用另一种方法来获取数据。例如,您的服务器应用程序可以使用 file_get_contents() 或另一个 PHP HTTP 客户端库从远程站点获取数据,然后在您自己的站点内发出数据(不带任何帧)。当然,如果您不拥有远程站点,则需要确保您可以通过这种方式重新使用他们的数据。

旧答案(如果您控制框架内的站点,请使用此答案:

解决此问题的典型方法是将所有框架中的 URL 指向新的框架集 URL,并使用target="_top",通常包含查询字符串参数来告诉框架集页面要加载哪些框架,

例如,想象 framset /frameset.php 最初指向两个框架。在 /frame1.php/frame2.php 中,frame1 内的链接应如下所示:

<a href="/frameset.php?frame1=link_url&frame2=frame2_current_url" target="_top">

其中 link_url 是您要加载的内容页面。到该框架中,frame2_current_url是当前加载到frame2中的url(因为您不希望它在页面重新加载时发生更改)

然后您需要更改父框架集的代码以查看。对于这些查询字符串参数,并相应地设置每个框架的 URL,如果未提供查询字符串参数,请确保对您填充到查询字符串参数中的所有 URL 进行 URL 编码。

请注意,您只想对指向您自己网站上的链接的链接执行此魔术。对于指向外部站点的链接,您根本不应该重写 URL,因此您最终会得到以下超链接:

<a href="http://www.externalsite.com/" target="_top">

警告:此方法实际上只适合您对生成的所有 URL 具有非常严格控制的站点。真正的网站往往有更宽松的控制,特别是如果您有非开发人员贡献内容或者您通过客户端脚本进行一些导航。

EDIT:

If you want to display a frame from another site and you can control how that other site emits its HTML, then follow the instructions in my original answer below to get the frames to emit hyperlinks with target="_top".

If, however, you're framing a site you don't have control over, then using frames is probably not going to work. Instead, you'll need to use another approach to get the data. For example, your server app could use file_get_contents() or another PHP HTTP client library to fetch the data from the remote site, and then emit the data (without any frames) inside your own site. Of course, if you don't own the remote site, you'll need to make sure it's OK for you to re-use their data in this way.

OLD ANSWER (USE THIS IF YOU CONTROL THE SITE(S) INSIDE THE FRAME(S):

The typical way to get around this is to point URLs in all frames at a new frameset URL, with target="_top" on the hyperlinks, typically containing query string parameters to tell the frameset page what frames to load.

For example, imagine framset /frameset.php with two frames initially pointed at /frame1.php and /frame2.php. Links inside frame1 should look like this:

<a href="/frameset.php?frame1=link_url&frame2=frame2_current_url" target="_top">

Where link_url is the content page you want to load into that frame, and frame2_current_url is the url currently loaded into frame2 (because you don't want it to change when the page is reloaded).

Then you need to change the code for your parent frameset to look for those query string parameters and set the URLs of each frame accordingly, using the default URLs for each frame if the query string parameters are not provided. Make sure to URL-encode all URLs you stuff into in query string parameters.

Note that you only want to do this magic for links pointing to links on your own site. For links to external sites, you shouldn't rewrite the URLs at all, so you'd end up wtih hyperlinks this:

<a href="http://www.externalsite.com/" target="_top">

Caveat: this approach is really only suited to sites where you have very tight control over all URLs that are generated. Real web sites tend to have looser control, especially if you have non-developers contributing content or if you do some navigation via client-side script.

倾其所爱 2024-10-20 00:16:52

<a href="foo" target="_top">

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