Dragen Posted April 27, 2007 Share Posted April 27, 2007 Okay, I know I'm gonna get loads of "it can't be done!" comments, but.... I've got a javascript which opens up a file in a new window.. now I would just use <a href="mylink" target="_blank"> But I want to specify the width and height of the pop-up. So this is what my javascript link looks like: <a href="javascript:void(0)" onclick="window.open('help.php', 'newWindow', 'scrollbars=1,resizable=1,height=500,width=600');"> I can easily add more variables in the function to send to the opened page.... I know php is server side and javascript is client, but if the javascript is being outputted before the php, because it's opening the file... could I not somehow pass a variable from the javascript function to a php function? Quote Link to comment https://forums.phpfreaks.com/topic/48907-solved-opening-file-with-javascript-and-passing-variables-to-php-probably-not/ Share on other sites More sharing options...
redbullmarky Posted April 27, 2007 Share Posted April 27, 2007 maybe it's just me but I really don't follow...can you try and explain differently? maybe give an example of exactly what you're trying to achieve? Quote Link to comment https://forums.phpfreaks.com/topic/48907-solved-opening-file-with-javascript-and-passing-variables-to-php-probably-not/#findComment-239660 Share on other sites More sharing options...
taith Posted April 27, 2007 Share Posted April 27, 2007 the "only" way of passing variables from javascript to php(other then via post/get)... is by cookies... your javascript sets a cookie, with some information, your php picks it up. Quote Link to comment https://forums.phpfreaks.com/topic/48907-solved-opening-file-with-javascript-and-passing-variables-to-php-probably-not/#findComment-239661 Share on other sites More sharing options...
Dragen Posted April 27, 2007 Author Share Posted April 27, 2007 okay.. sorry. I have some javascript which opens a file in a new window at the dimensions where it says height=500,width=600 in the onclick. What I want to do is use the javascript to open this file as I am already, but pass some variables to the page that php can read. If I add an extra variable to the javascript function: onclick="window.open('help.php', 'newWindow', 'scrollbars=1,resizable=1,height=500,width=600', '$myfunction');" Can I somehow get the php in the new file to read the variable from the javascript function? I thought that as the javascript is being used to open a file before the file has been accessed on the server I may be able to pass the variable to it at the same time as opening it.... Hopefully that makes more sense. Quote Link to comment https://forums.phpfreaks.com/topic/48907-solved-opening-file-with-javascript-and-passing-variables-to-php-probably-not/#findComment-239662 Share on other sites More sharing options...
Dragen Posted April 27, 2007 Author Share Posted April 27, 2007 Taith.. how can I use post with javascript? I presume it would still need a form to process it? Quote Link to comment https://forums.phpfreaks.com/topic/48907-solved-opening-file-with-javascript-and-passing-variables-to-php-probably-not/#findComment-239666 Share on other sites More sharing options...
redbullmarky Posted April 27, 2007 Share Posted April 27, 2007 as taith said, get/post/cookie are really your only options. Personally, if I want to pass info into a popup, just use the URL unless there's a reason why not: so instead of just: help.php , you'd have help.php?var=value&anothervar=anothervalue then just use $_GET to pick them up from within help.php itself. Quote Link to comment https://forums.phpfreaks.com/topic/48907-solved-opening-file-with-javascript-and-passing-variables-to-php-probably-not/#findComment-239669 Share on other sites More sharing options...
Dragen Posted April 27, 2007 Author Share Posted April 27, 2007 yeah.. I was trying to stay away from using the get method, but I guess I'll have to. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/48907-solved-opening-file-with-javascript-and-passing-variables-to-php-probably-not/#findComment-239673 Share on other sites More sharing options...
taith Posted April 27, 2007 Share Posted April 27, 2007 ya... javascript forcing $_POST... its not easy... but is doable, and no... javascript's window.open() doesnt pass variables, it only passes the configuration of the browser... your best choice... is either setting the cookies, or using $_GET Quote Link to comment https://forums.phpfreaks.com/topic/48907-solved-opening-file-with-javascript-and-passing-variables-to-php-probably-not/#findComment-239677 Share on other sites More sharing options...
Dragen Posted April 27, 2007 Author Share Posted April 27, 2007 thanks. I'm not wanting to set cookies as it's a bit pointless creating cookies for what I want, especially if the user has cookies disabled. I'm just going to go with the get method. thanks Quote Link to comment https://forums.phpfreaks.com/topic/48907-solved-opening-file-with-javascript-and-passing-variables-to-php-probably-not/#findComment-239681 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.