Dragen Posted April 18, 2007 Share Posted April 18, 2007 Hi, I've got a function which echos the html for a page. the function is written as function sampleview($category,$imagepth){ so it takes the two variables when called. This function is in a file called functions.php which is included on all of my pages. On one page I'm using Javascript to open up a new window which contains the same html as the php function.. I'm trying to transfer it all to php. The problem I've got is, I'm not sure how to use php to create a link that will open a new window at a preset size.. I can easily do echo "<a href=\"mypage.php\" target=\"_blank\">click here</a> but that will just open a new window. I need to specify the height and width of the window.. I also need the link to somehow call the function, instead of loading a page like; <a href="sampleview(mycategory,myimage)">click here</a> Is this possible? Link to comment https://forums.phpfreaks.com/topic/47547-calling-a-function-from-a-url/ Share on other sites More sharing options...
kenrbnsn Posted April 18, 2007 Share Posted April 18, 2007 You can't. PHP doesn't interact with the browser, since it runs on the SERVER and doesn't know or care where the output is going. The only way to do what you want to do is to use AJAX. Ken Link to comment https://forums.phpfreaks.com/topic/47547-calling-a-function-from-a-url/#findComment-232065 Share on other sites More sharing options...
Dragen Posted April 18, 2007 Author Share Posted April 18, 2007 well that's what I thought, but is there no way of sending the variables to the function? Lets say I use javascript to open the pop-up window, could I somehow pass the variables through with the javascript? This is the javascript function I've got: LoadImage('mycategory', 'myimage', 700, 500); return false" Could I get the php to read the first 2 values? Link to comment https://forums.phpfreaks.com/topic/47547-calling-a-function-from-a-url/#findComment-232075 Share on other sites More sharing options...
kenrbnsn Posted April 18, 2007 Share Posted April 18, 2007 PHP is long gone by the time Javascript executes. What does the LoadImage function look like? Ken Link to comment https://forums.phpfreaks.com/topic/47547-calling-a-function-from-a-url/#findComment-232083 Share on other sites More sharing options...
Dragen Posted April 18, 2007 Author Share Posted April 18, 2007 var popbackground="" //specify backcolor or background image for pop window //var windowtitle="" //pop window title function detectexist(obj){ return (typeof obj !="undefined") } function LoadImage(downloadtype, imgpath, popwidth, popheight){ var winattributes='width='+popwidth+',height='+popheight+',resizable=no,left=10,top=10' var bodyattribute=(popbackground.indexOf(".")!=-1)? 'background="'+popbackground+'"' : 'bgcolor="'+popbackground+'"' if (typeof ImageOpen=="undefined" || ImageOpen.closed) ImageOpen=window.open("","",winattributes) else{ //getpos() //uncomment these 2 lines if you wish subsequent popups to be centered too //jkpopwin.moveTo(leftpos, toppos) ImageOpen.resizeTo(popwidth, popheight+30) } ImageOpen.document.open() ImageOpen.document.write('<html><head><title>Downloads:'+downloadtype+' ~ '+imgpath+':.</title>'); ImageOpen.document.write('<link href="/main.css" rel="stylesheet" type="text/css" /></head>'); ImageOpen.document.write('<body '+bodyattribute+'>'); ImageOpen.document.write('<table border="0" cellpadding="0" cellspacing="0" align="center">'); ImageOpen.document.write('<tr><td><img src="downloads/'+downloadtype+'/'+imgpath+'/sample1.gif" /></td>'); ImageOpen.document.write('<td><img src="downloads/'+downloadtype+'/'+imgpath+'/sample2.gif" /></td></tr>'); ImageOpen.document.write('<tr><td><img src="downloads/'+downloadtype+'/'+imgpath+'/sample3.gif" /></td>'); ImageOpen.document.write('<td><img src="downloads/'+downloadtype+'/'+imgpath+'/sample4.gif" /></td></tr></table>'); ImageOpen.document.write('<center class="main">This is a screenshot of '+imgpath+'</center><hr color="#8e8989" size="1px" />'); ImageOpen.document.write('</body></html>') ImageOpen.document.close() ImageOpen.focus() } although I'm wanting to do all the ImageOpen.document.write in php Link to comment https://forums.phpfreaks.com/topic/47547-calling-a-function-from-a-url/#findComment-232090 Share on other sites More sharing options...
rcorlew Posted April 18, 2007 Share Posted April 18, 2007 Couldn't you combine the Imageopen function into a string and then post that to the next page by echoing it as a variable? Link to comment https://forums.phpfreaks.com/topic/47547-calling-a-function-from-a-url/#findComment-232176 Share on other sites More sharing options...
Dragen Posted April 18, 2007 Author Share Posted April 18, 2007 is imageopen javascript or php? Link to comment https://forums.phpfreaks.com/topic/47547-calling-a-function-from-a-url/#findComment-232214 Share on other sites More sharing options...
rcorlew Posted April 18, 2007 Share Posted April 18, 2007 Imageopen is javascript. To pass it to another page just make it a string like this: <?php $iopen = " ImageOpen.document.open() ImageOpen.document.write('<html><head><title>Downloads:'+downloadtype+' ~ '+imgpath+':.</title>'); ImageOpen.document.write('<link href="/main.css" rel="stylesheet" type="text/css" /></head>'); ImageOpen.document.write('<body '+bodyattribute+'>'); ImageOpen.document.write('<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">'); ImageOpen.document.write('<tr><td><img src=\"downloads/'+downloadtype+'/'+imgpath+'/sample1.gif\" /></td>'); ImageOpen.document.write('<td><img src=\"downloads/'+downloadtype+'/'+imgpath+'/sample2.gif\" /></td></tr>'); ImageOpen.document.write('<tr><td><img src=\"downloads/'+downloadtype+'/'+imgpath+'/sample3.gif\" /></td>'); ImageOpen.document.write('<td><img src=\"downloads/'+downloadtype+'/'+imgpath+'/sample4.gif\" /></td></tr></table>'); ImageOpen.document.write('<center class="main">This is a screenshot of '+imgpath+'</center><hr color=\"#8e8989\" size=\"1px\" />'); ImageOpen.document.write('</body></html>') ImageOpen.document.close() ImageOpen.focus() "; //Then when you need the function to be called after the variables are filled echo "$iopen"; ?> Link to comment https://forums.phpfreaks.com/topic/47547-calling-a-function-from-a-url/#findComment-232355 Share on other sites More sharing options...
per1os Posted April 18, 2007 Share Posted April 18, 2007 Imageopen is javascript. To pass it to another page just make it a string like this: <?php $iopen = " ImageOpen.document.open() ImageOpen.document.write('<html><head><title>Downloads:'+downloadtype+' ~ '+imgpath+':.</title>'); ImageOpen.document.write('<link href="/main.css" rel="stylesheet" type="text/css" /></head>'); ImageOpen.document.write('<body '+bodyattribute+'>'); ImageOpen.document.write('<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">'); ImageOpen.document.write('<tr><td><img src=\"downloads/'+downloadtype+'/'+imgpath+'/sample1.gif\" /></td>'); ImageOpen.document.write('<td><img src=\"downloads/'+downloadtype+'/'+imgpath+'/sample2.gif\" /></td></tr>'); ImageOpen.document.write('<tr><td><img src=\"downloads/'+downloadtype+'/'+imgpath+'/sample3.gif\" /></td>'); ImageOpen.document.write('<td><img src=\"downloads/'+downloadtype+'/'+imgpath+'/sample4.gif\" /></td></tr></table>'); ImageOpen.document.write('<center class="main">This is a screenshot of '+imgpath+'</center><hr color=\"#8e8989\" size=\"1px\" />'); ImageOpen.document.write('</body></html>') ImageOpen.document.close() ImageOpen.focus() "; //Then when you need the function to be called after the variables are filled echo "$iopen"; ?> Make sure you escape ALL the double quotes in the above. Link to comment https://forums.phpfreaks.com/topic/47547-calling-a-function-from-a-url/#findComment-232358 Share on other sites More sharing options...
rcorlew Posted April 18, 2007 Share Posted April 18, 2007 Oops I missed a few at the top, I'm sorry. Link to comment https://forums.phpfreaks.com/topic/47547-calling-a-function-from-a-url/#findComment-232366 Share on other sites More sharing options...
Dragen Posted April 20, 2007 Author Share Posted April 20, 2007 hmmm.. I took a couple of days to get back to you all.. sorry guys! I think I'm just gonna leave it as javascript for now. It's not a major feature of my site and wont really matter if a user can't load it if they have javascript disabled. Link to comment https://forums.phpfreaks.com/topic/47547-calling-a-function-from-a-url/#findComment-234138 Share on other sites More sharing options...
taith Posted April 20, 2007 Share Posted April 20, 2007 php is done executing way before your computer even touches the file(apache not withstanding)... the "only" way you can get javascript, to run a php function... is by ajax... 1 - javascript function builds ajax query 2 - ajax loads php page 3 - php returns data to ajax->javascript 4 - javascript back to html Link to comment https://forums.phpfreaks.com/topic/47547-calling-a-function-from-a-url/#findComment-234146 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.