PHP (or Javascript) Sending variable to pop-up page

Hi,

I have a page with a button link on it. When the user clicks this link it opens a feedback page. I want the url of the sending page to be sent to the feedback page so I know when I get the email what page it was from. If this button is not part of the form on the page can it only be done through Javascript? Would someone to kind enough to suggest a solution to me?

Thanks guys,

D
jones_bonesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Cyber-DrugsCommented:
As far as I know, you cannot just send a variable to a pop-up window. You have two methods to approach this:

(Before opening the window)
When opening the popup window, pass in the filename, some query arguments, which PHP will read as your variables, eg:

window.open('mypage.php?variable1=abc&variable2=def');


(After opening the window)
You can have a timer running in the window, which every few seconds, checks an XML file (or database), with AJAX to look for variables to read and make use of. And on the window where you want to send the variable from, you would obviously just write the variable(s) to the XML document, or database.



I hope this helped.
0
AnniyanCommented:
$var = $_SERVER['HTTP_REFERER']

will give you the URL of the page from which the user landed on the current page.
0
jones_bonesAuthor Commented:
Thanks guys for the quick response,

Here is what I have now under the form:

<a href="javascript:window.open('fw_feedback.php?$variable1=$var');">Do you have another answer? Click here to submit it</a>

Annivan, I have the $var variable assigned as you suggested above. When I try to echo either of these variables on the receiving page it comes up blank. What am I doing wrong?

Also, is there a way to keep the current page open? When the pop-up page opens the current page changes to [object]

Thanks guys,

D
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Cyber-DrugsCommented:
Unfortunately, I mis-read your question.

Anniyan, gave the better solution for what you are after.

As for $var coming up blank, have you checked the source code to see if it's actually working at all, and is just not being displayed on the webpage?
0
jones_bonesAuthor Commented:
Sorry yeah,

I was trying to put the two solutions together and put the php referrer on the wrong page. Only problem now so is the

[object] that appears on the sending page after the pop-up opens?

Also, how do I define the size of the pop-up window when using the window.open function?

Thanks,

D
0
jones_bonesAuthor Commented:
It changes the sending page url to javascript:window.open('fw_feedback.php');

Does that mean it is not defined as a pop-up window?
0
Michel PlungjanIT ExpertCommented:
NEVER use the javascript: protocol if you want to stay on the page
Use onClick and return false

<a href="#"
onClick="window.open('fw_feedback.php?page='+escape(location.href)+'&title'+escape(document.title),'_blank','width=500,height=500');
return false">Do you have another answer? Click here to submit it</a>
0
Michel PlungjanIT ExpertCommented:
Here is a php way:

http://whn.vdhri.net/2005/11/how_to_find_the_current_url_with_php.html


<?php
 $domain = $_SERVER['HTTP_HOST'];
  // find out the path to the current file:
  $path = $_SERVER['SCRIPT_NAME'];
  // find out the QueryString:
  $queryString = $_SERVER['QUERY_STRING'];
  // put it all together:
  $url = "http://" . $domain . $path . "?" . $queryString;
?>


<a href="fw_feedback.php?page=<? echo $url; ?>" target="_blank"
onClick="var w=window.open(this.href,this.target,'width=500,height=500');
return (w)?false:true">Do you have another answer? Click here to submit it</a>

The above will open a popup if allowed - if not, the feedback page is loaded anyway
0
jones_bonesAuthor Commented:
Thanks mplungjan,

Thats working now. Just one small thing though. As its a quiz I don't want the possibility that the user could loose the page theire on if they leave another answer through the pop-up page. Therefore I would prefer to put in a let help icon that says "please allow pop-ups on this page" rather than having them leave the page altogether. Would it be difficult to alter the php code so that if pop-ups are disabled the page does not re-direct?

Thanks,

D
0
Michel PlungjanIT ExpertCommented:
If they have popups blocked, the target will give them a new window (or tab if they open their new windows in  new tabs)
The last code I posted will not redirect them from the question regardless of popups blocked, js turned off or whatever

If you DO want a warning, try this

<a href="why_you_should_allow_javascript.html" target="_blank"
onClick="var w=window.open('fw_feedback.php?page='+escape(location.href)+'&title'+escape(document.title),'_blank','width=500,height=500');
if (!w) alert('Please allow popups on this page'); return false">Do you have another answer? Click here to submit it</a>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jones_bonesAuthor Commented:
Legend! Thanks for your help. Thats perfect
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.