Jump to content

What is wrong with this bit o code?


SharkBait

Recommended Posts

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

[code]
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 + '')");
}
[/code]

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

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

Link to comment
https://forums.phpfreaks.com/topic/23176-what-is-wrong-with-this-bit-o-code/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.