Jump to content

calling a function from a url?


Dragen

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.