Web Analytics Made Easy -
StatCounter hoped i can do it with PHP but need javascript- passing a variable - CodingForum

Announcement

Collapse
No announcement yet.

hoped i can do it with PHP but need javascript- passing a variable

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • hoped i can do it with PHP but need javascript- passing a variable

    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 Code:

    <?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

  • #2
    Javascript can access the opening window if the current window was opened via window.open().

    in the popup

    Code:
    alert( window.opener.location.href );
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

    Comment


    • #3
      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?

      Comment


      • #4
        Ok, let's back up. In a normal page hop, the HTML headers include a referrer, as you mention grabbing with PHP
        Code:
        +---+      +---+
        | 1 | -+-> | 2 |
        +---+  |   +---+
               |
        referrer header is passed
        Now, when we use window.open to create a new window, the referrer header isn't passed.
        Code:
        +---+      +---+
        | 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:
        Code:
        <script type="text/javascript">
            var page1url = window.opener.location.href;
        </script>
        Understand better?
        My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
        “Minds are like parachutes. They don't work unless they are open”
        “Maturity is simply knowing when to not be immature”

        Comment


        • #5
          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?

          Comment


          • #6
            Well, if you're opening the link with javascript - the target attribute is moot.

            And yes, your "open browser javascript" goes in Page 1
            My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
            “Minds are like parachutes. They don't work unless they are open”
            “Maturity is simply knowing when to not be immature”

            Comment


            • #7
              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?
              Last edited by grudz; Feb 16, 2004, 10:44 AM.

              Comment


              • #8
                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;

                Comment


                • #9
                  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

                  Comment


                  • #10
                    Ya, but I wouldn't use MM_openBrWindow as the variable choice - choose something semantic.
                    Code:
                    var openerURL = window.opener.location.href;
                    Do you have this online someplace? That would make debugging MUCH easier.
                    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
                    “Minds are like parachutes. They don't work unless they are open”
                    “Maturity is simply knowing when to not be immature”

                    Comment


                    • #11
                      yeah heres the link

                      http://www.mtl-baseline.com/establis...lub%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

                      Comment


                      • #12
                        Looks fine to me. However, you capture the value of the opener's URL, but you don't do anything with it.
                        Code:
                        <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?
                        My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
                        “Minds are like parachutes. They don't work unless they are open”
                        “Maturity is simply knowing when to not be immature”

                        Comment


                        • #13
                          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

                          Comment


                          • #14
                            k i got it....i changed the name of the script to page1url.....thanx....i really appreciate all the help

                            Comment

                            Working...
                            X