0
   

Javascript noob needs to combine scripts

 
 
Reply Wed 1 Oct, 2014 09:14 am
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.

I have now considered that POST is the best way to do this as the variable will not be pased in a bookmark or favourite (at least I think or hope, unless the browser remebers it and asks to "repost data" )

I think I have figured out the basics but the mechanics involve JavaScript that I am not so familiar with.

Here is what I have in a page right now that opens a new window centered
Code:
<script>
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);

}
</script>

<a onclick="PopupCenter('/customconfig/index.php, 'CustomBuilder1',1080,700);" href="javascript:void(0);"> <img border=0 src = "/images/Animated.GIF"></a>


Now I want to combine this kind of code to pass the POST variable ( taken from http://mentaljetsam.wordpress.com/2008/06/02/using-javascript-to-post-data-between-pages/ ), but I need the following merged with the former and do not know how to do that. I also only need to post one fixed variable liike javawindow='yes'

Code:
<script>
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) ;

}
</script>


As I said, I believe if I can find a way to merge these two successfully, it will do exactly what I need . In other places people keep suggesting is use ajax or jquery but I do not want to learn the entire German language to be able to say "Guuten Tag"

Thanks in advance,

Mark
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Question • Score: 0 • Views: 1,816 • Replies: 0
No top replies

 
 

 
  1. Forums
  2. » Javascript noob needs to combine scripts
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.04 seconds on 04/25/2024 at 06:44:58