PDA

View Full Version : hoped i can do it with PHP but need javascript- passing a variable



grudz
Feb 13th, 2004, 08:04 PM
Hello,

i need to figure out a way to pass the variable
$_SERVER['HTTP_REFERRER'] to another page.

Here's my situation without javascript. I could pass that variable very easy if i do target:_blank with my link. However, i need to set the widht and height of the new window, so i need javascript. However, with that, my




<?php echo $_SERVER['HTTP_REFERER'] ?>



wont pass. its like i have to make a choice: do target:_blank and pass the variable or do a open browser window javascript without the variable passing?

Can i have both

(i dont know much about javascript but if $_SERVER['HTTP_REFERER'] means the same, great, if not, in php that gives you the url of the page that you came in from)

thank you in advance

beetle
Feb 13th, 2004, 08:07 PM
Javascript can access the opening window if the current window was opened via window.open().

in the popup



alert( window.opener.location.href );

grudz
Feb 13th, 2004, 08:11 PM
i dont want to sound like an idiot but i know almost nothing of javascript so if i copy/paste the code u gave me

alert( window.opener.location.href );


i have to change location to _blank and href to the new window?

anything else?

beetle
Feb 13th, 2004, 08:21 PM
Ok, let's back up. In a normal page hop, the HTML headers include a referrer, as you mention grabbing with PHP


+---+ +---+
| 1 | -+-> | 2 |
+---+ | +---+
|
referrer header is passed

Now, when we use window.open to create a new window, the referrer header isn't passed.


+---+ +---+
| 1 | -+-> | 2 |
+---+ | +---+
|
referrer header is NOT passed

In this scenario, Page 1 is the opener of Page 2. So, in the HTML for Page 2, we can reference Page 1 (and all it's properties) with javascript. To get the URL of Page 1, for example:


<script type="text/javascript">
var page1url = window.opener.location.href;
</script>

Understand better?

grudz
Feb 16th, 2004, 03:31 PM
ok i understand, so i got to put the code in page 2, as for the location, i put what? _blank? and href is the url of page 1?......and that code, i just put it in the header and then i have my normal javascript open browser window script in page 1?

beetle
Feb 16th, 2004, 03:35 PM
Well, if you're opening the link with javascript - the target attribute is moot.

And yes, your "open browser javascript" goes in Page 1

grudz
Feb 16th, 2004, 03:40 PM
ok, so i dont but target, what do i put for location? oh and i forgot, the href could be many things, something like this mysite.com/name.php?name=myname (everything up until name=, stays the same, but after the url is going to change, what do i do in this case?

Garadon
Feb 16th, 2004, 04:09 PM
if put in page 2 this gets the url written in address bar of page1
there is nothing that should be replaced.

window.opener.location.href;

grudz
Feb 16th, 2004, 04:18 PM
oh....ok....that makes sense. One last question though (i hope) because it still doesnt work. this is my code in the first page

function MM_openBrWindow(theURL,winName,features) { //v2.0
window.open(theURL,winName,features);
}

so that means instead that my code for page 2 has to be

<script type="text/javascript">
var MM_openBrWindow = window.opener.location.href;
</script>


??? is that correct

beetle
Feb 16th, 2004, 04:22 PM
Ya, but I wouldn't use MM_openBrWindow as the variable choice - choose something semantic.
var openerURL = window.opener.location.href;Do you have this online someplace? That would make debugging MUCH easier.

grudz
Feb 16th, 2004, 04:25 PM
yeah heres the link

http://www.mtl-baseline.com/establishment.php?name=Club%20Crescent

click on the "email to friend", the text box to the left of the "submit" button has to have the url that of the first page

thanx

beetle
Feb 16th, 2004, 04:31 PM
Looks fine to me. However, you capture the value of the opener's URL, but you don't do anything with it.
<script type="text/javascript">
onload = function()
{
var page1url = window.opener.location.href;
document.forms['emailfriend'].elements['referer'].value = page1url;
}
</script>
Were you just expecting it to magically happen for you? :rolleyes:

grudz
Feb 16th, 2004, 04:34 PM
:) no when the user clicks submit, it goes to another php script that sends the email, that works fine......but when u went on it, did u see the link in the textbox next to the submit button, cuz i dont

grudz
Feb 16th, 2004, 04:36 PM
k i got it....i changed the name of the script to page1url.....thanx....i really appreciate all the help