Jump to content


Photo

What is wrong with this bit o code?


  • Please log in to reply
3 replies to this topic

#1 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 06 October 2006 - 01:31 PM

Firefox runs this bit of code fine with no errors in the javascript console, but IE fails and doesn't want to execute it:

function ShowImage(URL, WIDTH, HEIGHT) {
	// Get URL and image size from PHP
	
	// Get width of currently open window
	var w = document.body.clientWidth;
	var h = document.body.clientHeight;
	
	// Center Window
	var leftPos = (w - WIDTH)/2, topPos = (h - HEIGHT) /2;
	
	// Add to the width and height to show images properly
	WIDTH = WIDTH + 25;
	HEIGHT = HEIGHT + 25;
	
	// Create a somewhat unique ID number for the window
	id = <?php echo rand(900, 999);?>
	// Open up a window and display the image.
	eval("page" + id + " = window.open(URL, '" + id + "','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=' + WIDTH + ',height=' + HEIGHT + ',left = ' + leftPos + ',top = '+ topPos + '')");
}

It is called via:
<?php
echo "<a href=\"javascript:ShowImage('photos/{$photos['filename']}', $width, $height);\"><img src=\"photos/thumb_{$photos['filename']}\" alt=\"{$photos['filename']}\" border=\"=\" /></a> ";
?>

All the parameters get passed, so I am not sure what is wrong.  On http://www.tingram.ca the IE javascript error window says
Line: 1
Char: 1
Error: Object Expected
Code: 0
URL: http://tingram.ca



#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 06 October 2006 - 01:42 PM

First, the code is fine, and executes on IE (at least with dummy input); the link you posted has other syntax errors.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 06 October 2006 - 02:13 PM

There is a WYSIWYG editor I use that is javascript based.  Would that effect the popup window I am trying to do with JS?

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 06 October 2006 - 03:19 PM

Not sure... but you have to fix that syntax error first.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users