title: Javascript POST to PHP page
body: <p>My goal is to establish whether a page was opened via a JavaScript pop-up, and carry a related URL variable through to other page(s). Originally I thought I could do this with a URL variable however as JavaScript runs client-side and php is server-side there is no way to verify whether the window is a JavaScript window especially given the possibility that someone returned on a favorite or bookmark.</p>
  
  <p>I originally made a similar post to this however as the idea has evolved and being stuck with the variable in the URL, this may be a better approach.</p>
  
  <p>I think I have figured out the basics but the mechanics involve JavaScript that I am not so familiar with.</p>
  
  <p>Here is what I have in a page right now</p>
  
  <pre><code>&lt;script&gt;
      function PopupCenter(pageURL, title,w,h) {
  
          var left = (screen.width/2)-(w/2);
          var top = (screen.height/2)-(h/2);
          var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no,  menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
  
      }
  &lt;/script&gt;
  
  &lt;a onclick="PopupCenter('/customconfig/index.php, 'CustomBuilder1',1080,700);" href="javascript:void(0);"&gt; &lt;img border=0  src = "/images/Animated.GIF"&gt;&lt;/a&gt;
  </code></pre>
  
  <p>Now I found this page <a href="http://mentaljetsam.wordpress.com/2008/06/02/using-javascript-to-post-data-between-pages/" rel="nofollow">http://mentaljetsam.wordpress.com/2008/06/02/using-javascript-to-post-data-between-pages/</a></p>
  
  <p>Which tells me how to put a POST in a JavaScript with this code:</p>
  
  <pre><code>&lt;script&gt;
      function postwith (to,p) { 
  
          var myForm = document.createElement("form");
          myForm.method="post" ;
          myForm.action = to ;
  
          for (var k in p) {
              var myInput = document.createElement("input") ;
              myInput.setAttribute("name", k) ;
              myInput.setAttribute("value", p[k]);
              myForm.appendChild(myInput) ;
          }
  
          document.body.appendChild(myForm) ;
          myForm.submit() ;
          document.body.removeChild(myForm) ;
  
      }
  &lt;/script&gt;
  </code></pre>
  
  <p>Of course the advantage of this method is that there is no URL variable when I go to the first page and I can also carry the POST value through all PHP pages.</p>
  
  <p>My biggest question is how to merge the code for loading the centered JavaScript window with the code for passing the POST variable, and making them work happily together.</p>
  
  <p>This means that if someone goes back on a bookmark or favorite the POST value will be NULL, and I can carry that NULL value through the subsequent page(s) as a POST hidden value.</p>
  
  <p>EDIT--------</p>
  
  <p>I guess I need to be clearer. I do not know much about java. I need to combine the existing java pop-up which centers the page with passing the POST. It seems doable and logical enough. Getting into AJAX which I know NOTHING about would only serve to confuse the issue further. I can not learn a new language every time I need to solve a problem.</p>