0

Been working on this since yesterday, having no success. I need to get the URL of a parent window into a form field on a child window so that I can send it along with customer from the form. Can anyone tell me how this can be done? I'd prefer it be done with PHP because I'm getting familiar with that.

Please and thanks.

If I did this on the parent page would it stor the parent's URL so that I could retreive it later?

<?php
$_SERVER['PHP_SELF'];
?>

and then to recall it on child perhaps:

   if(!empty($_SERVER['PHP_SELF'])){
    $link = $_SERVER['PHP_SELF'];
}else{
    $link = "No URL submitted.";
}
Scott Morrison
  • 153
  • 1
  • 8
  • Have you tried anything? Post some code. – Get Off My Lawn May 31 '13 at 17:03
  • I'm not sure where to begin. i'm thinking of two approaches. One would be getting the URL of the parent and saving as a session variable (but I haven't used session variables yet) the other is creating a function on parent that I can call from the child but that seems more complicated. – Scott Morrison May 31 '13 at 17:05
  • 1
    Take a look at this question: http://stackoverflow.com/questions/4413414/get-parent-location-url-iframe-from-child-to-parent – Get Off My Lawn May 31 '13 at 17:08
  • You can't use referrer? – Alice May 31 '13 at 17:10
  • 1
    From what I've read [REFERER] doesn't work on all browsers. – Scott Morrison May 31 '13 at 17:13
  • thanks for the link Ryan, but I'm sucha noob I don't know what to do with all that code. – Scott Morrison May 31 '13 at 17:13
  • @ScottMorrison this can't be done really well with php, it is possible but your best bet is to use JavaScript. Also, is this a popup window or an iFrame? – Get Off My Lawn May 31 '13 at 17:15
  • this is a popup window I created with javascript. I'm open to js is that's what it'll take. I'm just having trouble with the what page has to do what. I'm thinking that parent should store it's URL and child should some how retreive it. – Scott Morrison May 31 '13 at 17:34
  • If you know for certain that the URL of the parent window is deterministic, you can do it server side, because the server already knows the value of the parent window URL. If you want to do that client-side, then use Javascript to pass the info to the child page and send that back to the server. – taz May 31 '13 at 17:45
  • this may make this simpler, here is a product page, on it you'll see a "request product info" graphic, click it and a popup box comes up, in that box I'd like to have the URL of the product page automatically put into the "model" text field. https://www.taftfurniture.com/bedroom/bedroom-sets/bennington-master-bedroom-set – Scott Morrison May 31 '13 at 17:54

3 Answers3

0

is this about iframes?

If so, then:

  1. parent.document.location.href - to get url of the document where the iframe is placed

  2. top.document.location.href - get url of the document, whose url is in the address field of the browser

el Dude
  • 5,003
  • 5
  • 28
  • 40
0
var childPopup = window.open();

var childForm = childPopup.document.createElement('form');
childForm.setAttribute('action', 'serverurl');
childForm.setAttribute('method', 'POST');
childPopup.document.body.appendChild(childForm);

var childText = childPopup.document.createElement('input');
childText.setAttribute('type', 'text');
childText.setAttribute('value', document.location.href);

childForm.appendChild(childText);

This is an example of Javascript that gets the URL of the parent window into a form field of the child window. Then this URL will be sent to the server as a parameter when the form is submitted.

taz
  • 1,506
  • 3
  • 15
  • 26
0

have been working all day at this. apparently found at get parent.location.url - iframe - from child to parent

so you need <iframe src="http://your-site.com/framepage.php?parent=http://parentpage.com">

and in framepage.php (or whatever u has)

echo $_GET['parent'];
Community
  • 1
  • 1
jsHate
  • 499
  • 1
  • 3
  • 20