Jump to content

Archived

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

SharkBait

What is wrong with this bit o code?

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]

Share this post


Link to post
Share on other sites
First, the code is fine, and executes on IE (at least with dummy input); the link you posted has other syntax errors.

Share this post


Link to post
Share on other sites
There is a WYSIWYG editor I use that is javascript based.  Would that effect the popup window I am trying to do with JS?

Share this post


Link to post
Share on other sites
Not sure... but you have to fix that syntax error first.

Share this post


Link to post
Share on other sites

×

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.