开发者

Maintain an iframe context

My first post here! My question relates to iframes and php mostly

So... it's impossible for PHP to check if a page was requested through an iframe. This quest开发者_Python百科ion seems to be asked (and answered) a lot, but would it be possible to create an "iframe context" and maintain that context throughout the navigation within an iframe?

For example :

<iframe src="/my/url?location=iframe"></iframe>

we could initially check if ($_GET['location'] == 'iframe')

however, as navigation goes on, you can imagine what happens. Links are click, forms are submitted, and they don't necessarily have ?location=iframe.

So, I'm trying to figure out how to create an initial context that begins with the url parameter above and persists within the iframe only.

Just to be clear, in my example the iframe contains pages from the same site.

Thanks for your help.


What if you set the initial URL to /iframe/my/url when it's loaded in an iframe, and /my/url when it isn't, and either:

  • Create a symlink (or an NTFS junction) in your document root called 'iframe' that points to your document root and parse $_SERVER['PHP_SELF']
  • use mod_rewrite to rewrite the URL so it points to the right place and has the location=iframe or maybe #iframe tagged onto it

The first option is probably the best, although all your paths would have to relative. This means all your paths will stay within the /iframe/ path and you never need to alter your links - everything is processed for you.


You could put this in a document ready function and add #iframe as a hash to all links on the page. then use php to check for the hash

$('a').each(function(){
    this.attr('href',this.attr('href')+'#iframe');
});
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜