Auto Resizing

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Auto Resizing

Post by John Cartwright »

Hmmm I've been googling for awhile and couldn't figure out a way to auto resize a popup to fit to a picture.

This is what I got so far

Code: Select all

function popup()
{ 
window.open('large_pics/clantemp1.jpg','','width=1,height=1,menubar=no,scrollbars=no,toolbar=no,location=no,directories=no,resizable=no,top=0,left=0'); 
}

//-->
</SCRIPT>
Note I set the width and height to 1 because I read somewhere that it will obviously resize to the picture but it doesntt.

Any help much appreciated TY
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

untested..

Code: Select all

<html>
<head><script language="Javascript 1.2"><!--
function autoResize(id)
&#123;
  var obj = document.getElementById ? document.getElementById( id ) : document.all&#1111; id ];
  if( obj && self.resizeTo )
  &#123;
    self.resizeTo(obj.width + 10, obj.height + 10);
  &#125;
&#125;
//--></script></head>
<body onload="autoResize('imageID')"><img id="imageID" src="someimage.jpg" /></body>
</html>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I'm a bit confused by this: what is ID refering to?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

if this script works the way I think it is it woulnd't work...

because the image is always changing depending on which picture is clicked.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the calling script can either call a php script that writes this code, or can directly write the code to the window.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

okay sorry feyd i was looking at the script all wrong but it still isn't working..... also I want it so you cannot see the scrollbar, toolbars etc etc ... i only know how to do that with window open :(
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

combine yours and mine like so:
untested

Code: Select all

function popup(file)
&#123;
  window.open('popup.php?file='+file,'','width=1,height=1,menubar=no,scrollbars=no,toolbar=no,location=no,directories=no,resizable=no,top=0,left=0');
&#125;
popup.php:

Code: Select all

<?php

if(!isset($_GET['file']))
  die('No peeking!');

$file = $_GET['file'];

$html = <<<STOP
<html>
<head><script language="Javascript 1.2"><!--
function autoResize(id)
{
  var obj = document.getElementById ? document.getElementById( id ) : document.all[ id ];
  if( obj && self.resizeTo )
  {
    self.resizeTo(obj.width + 10, obj.height + 10);
  }
}
//--></script></head>
<body onload="autoResize('imageID')"><img id="imageID" src="{S_IMAGEFILE}" /></body>
</html>
STOP;

$output = str_replace('{S_IMAGEFILE}',$file,$html);

echo $output;

?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

wow ty alot man

but to be quite honest im useless with heredoc never gotten them to work
Parse error: parse error, unexpected T_SL in C:\apachefriends\xampp\htdocs\j6\templates\main\popup.php on line 8
on popup.php
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

odd, it runs for me..
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

K this is my problem now...

I have to pass multiple vars in the header for the popup, so I use this link. Excuse the slopiness it's just so many quotes made it really dificult to put this all in 1 echo statement. So I break in and out of PHP.. atleast for now. But the problem is I'm getting OBJECT EXPECTED erorr when clicking on the link

Code: Select all

<a href='javascript: popup("large_pics/clantemp<?=$row['id'].$x."_".$_SESSION["{$row['id']}c"]?>.jpg");'><img src='small_pics/clantemp<?=$row['id'].$x."_".$_SESSION["{$row['id']}c"]?>.jpg' width='120' height='110' border='0' target='_blank'></a>
which will produce javascript: popup("large_pics/clantemp71_1.jpg");
and the function is

Code: Select all

&lt;SCRIPT TYPE="text/javascript" LANGUAGE="javascript"&gt;
&lt;!--

function popup(pic)
&#123; 
  window.open('popup.php?pic='+pic+,'','width=1,height=1,menubar=no,scrollbars=no,toolbar=no,location=no,directories=no,resizable=no,top=0,left=0'); 
&#125;

//--&gt;
&lt;/SCRIPT&gt;
Any help is much appreciated
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

hmm stupid me I had an extra + after pic

ty feyd;


edit: but now the page isnt resizing.... sorry I;m so clueless in this area but what can ya do! :P
Post Reply