开发者

Frameset causes URL to not change when navigating through the pages. Is there a way to get around this?

开发者 https://www.devze.com 2023-02-05 16:40 出处:网络
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 contai开发者_开发问答ns the frameset, the URL no lo

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 contai开发者_开发问答ns 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?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号