0

Is it possible to get the context, like the full URL, or the containing page path, title, etc., while inside an overlay page?

For example, I have a form pop up inside an overlay, and I want to, inside that form, be able to get the context of the page that triggered the overlay popup. I can't pass any information via the URL... I'd just like to be able to do something like arg(0) for the containing page (what's faded out in the background of the overlay.

Right now, if I do arg(0), request_uri(), $_GET['q'], etc., it always returns the overlay path, like http://www.example.com/path/i/want#overlay=overlay/path

(I want the 'path/i/want' portion of the URL, somehow).

| improve this question | | | | |
2

Unfortunately the PHP that's rendering the child page knows nothing about the parent page over which it's going to be placed. You could write an AJAX callback that checks window.location and reports back to the server, but that would have to run after the page was fully rendered.

| improve this answer | | | | |
  • Just posting back, since I've had a few people email me about this; in the end, I think I used a Ctools modal instead of Overlay.module to pass information between the modal and the page on which it appears. – geerlingguy Sep 14 '12 at 17:46
0

I recently struggled with the same question and found a possible solution using PHP. The path stored in $_GET will always return the child path of the overlay. Like in your example:

http://www.example.com/path/i/want#overlay=overlay/path

Using current_path() will return “overlay/path” not “/path/i/want#overlay=overlay/path”.

The good news is that the URL of the parent window is still stored in *$_SERVER['HTTP_REFERER']*. The bad news is that ‘HTTP_REFERER’ may not always be set…depending on the client browser configuration.

But if this is acceptable risk or it’s something you feel your application can compensate for, then you can get the parent path from *$_SERVER['HTTP_REFERER']*.

In my testing, 'HTTP_REFERER' returned the absolute path (e.g. http://www.example.com/path/i/want). If you want just the relative path, you can get it like so:

<?php
function mymodule_get_overlay_parent path() {
  global $base_url;
  // Get the HTTP Referer.
  $referer = $_SERVER['HTTP_REFERER'];  
  // Check for and remove the base url to return just the relative path.
  // Otherwise, return the referer as is.
  if (strpos($referer, $base_url) === 0) {
    $parent_path = substr($referer, strlen($base_url));    
  }
  else {    
    $parent_path = $referer;
  }

  return $parent_path;
}
?>
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.