473,322 Members | 1,501 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Script doesn't work in Firefox

Hi

The following code works fine in IE but not Firefox.
It's a little script that zooms an image and resizes the window to fit.
Can anybody tell me what's wrong?

Thanks
Nico

== btw.. sorry for the long post ==

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Aphrodite Hills</title>
<style type="text/css">
<!--
**SNIPPED**
-->
</style>

<script language="JavaScript">
<!--

function SymError()
{
return true;

}

window.onerror = SymError;

//-->
</script>

<script language="javascript"><!--
function window_resize(o_img, int_offset_h,
int_offset_w) {
table_all.style.visibility="hidden";
var int_max_h = window.screen.availHeight;
var int_max_w = window.screen.availWidth;
var int_size_h = o_img.height + int_offset_h;
int_size_h = (int_size_h > int_max_h) ?
int_max_h : int_size_h;
var int_size_w = o_img.width + int_offset_w;
int_size_w = (int_size_w > int_max_w) ?
int_max_w : int_size_w;
//window.moveTo(0,0);
int_size_w = (int_size_w>390)? int_size_w :
390;
window.resizeTo(int_size_w, int_size_h);
self.focus();
table_all.style.visibility="visible";
}

function resize(k) {
table_all.style.visibility="hidden";
self.o_img.width *= k;
self.o_img.height *= k;
window.resizeTo(self.o_img.width+50,
self.o_img.height+135);
table_all.style.visibility="visible";
}

function on_key_press() {
if (event.keyCode == "27") this.close();
else if (event.keyCode==43) resize(1.1);
else if (event.keyCode==45) resize(.9);
}
-->
</script>
</head>

<body onload="javascript:window_resize(self.o_img, 135, 50);"
onkeypress="on_key_press();">

<table id="table_all" height="100%" width="100%" border="0"
cellpadding="0" cellspacing="0">
<tr>
<td>
<table width="100%" border="0" cellpadding="0"
cellspacing="0">
<tr>
<td>
<div align="left"><nobr>
<img src="assets/magnify_plus.gif" style="cursor:hand"
onclick="javascript:resize(1.1);" WIDTH="107" HEIGHT="24">
<img src="assets/magnify_minus.gif" style="cursor:hand"
onclick="javascript:resize(.9);" WIDTH="117" HEIGHT="24">
<a style="cursor:hand" onClick="window.print();"><img
src="assets/print.gif" width="89" height="24" border="0"></a>

</nobr></div></td>
</tr>
</table>
</td>
</tr>
<tr height="1">
<td bgcolor="#DDDECC"><img SRC="assets/spacer_trans.gif"
width="1"
height="1"></td>
</tr>
<tr>
<td align="center" valign="middle">
<img src="assets/plot239/dev239.jpg" name="o_img" width="390"
height="310" hspace="5" vspace="5" border="0" align="top" id="o_img">
</td>
</tr>
</table>
</body>
</html>

Oct 13 '05 #1
3 2929
niconedz wrote:
Hi

The following code works fine in IE but not Firefox.
It's a little script that zooms an image and resizes the window to fit.
Not all users or all browsers will let you re-size the window, so expect
that it won't work at least sometimes.
Can anybody tell me what's wrong?
Normally you should explain what you consider 'wrong'. Did you get any
errors from the Firefox script console?

Thanks
Nico

== btw.. sorry for the long post ==
That's OK *if* you make it so the code can be copied and pasted into a
file, then run without error. Use 2 or 4 spaces for indents, not tabs
or 8 spaces or so. Manually break lines at about 70 characters to
prevent news readers from automatically breaking them and introducing
errors.

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Aphrodite Hills</title>
<style type="text/css">
<!--
**SNIPPED**
-->
</style>
For the sake of posting sample code, just ditch the style element
completely. Using HTML comment tags inside a style element may cause
problems of itself.

<script language="JavaScript">
The language attribute is depreciated, type is required:

<script type="text/javascript">
<!--
Don't use HTML comment tags inside script elements - they are
potentially harmful and have been unnecessary since about Netscape 2 and
IE 3 (let's say 10 years). ;-)

function SymError()
{
return true;

}

window.onerror = SymError;
Right here you destroy your chance to see the error messages that might
help you - it stops anything useful going to the Firefox script console.

<URL:http://www.mozilla.org/docs/dom/domref/dom_window_ref58.html>

//-->
</script>

<script language="javascript"><!--
function window_resize(o_img, int_offset_h,
int_offset_w) {
table_all.style.visibility="hidden";
Here's one error - using an ID attribute as a global variable:

var table_all = document.getElementById('table_all');

You should not assume support for the style object, so:

if (table_all.style) {
table_all.style.visibility = "hidden";
}

I guess strictly you should also test for getElementById and offer
document.all if it is not available, but that is only really necessary
if you want to support IE 4.
var int_max_h = window.screen.availHeight;
var int_max_w = window.screen.availWidth;
var int_size_h = o_img.height + int_offset_h;
int_size_h = (int_size_h > int_max_h) ?
int_max_h : int_size_h;
var int_size_w = o_img.width + int_offset_w;
int_size_w = (int_size_w > int_max_w) ?
int_max_w : int_size_w;
//window.moveTo(0,0);
int_size_w = (int_size_w>390)? int_size_w :
390;
window.resizeTo(int_size_w, int_size_h);
self.focus();
table_all.style.visibility="visible";
}

function resize(k) {
table_all.style.visibility="hidden";
Here it is again.
self.o_img.width *= k;
self.o_img.height *= k;
That method of referring to an image doesn't work in Firefox, though it
does support the images collection (as do nearly all browsers) 'cos it's
part of DOM 0:

var o_img = document.images['o_img'];
o_img.width *= k;
...
window.resizeTo(self.o_img.width+50,
self.o_img.height+135);
table_all.style.visibility="visible";
}

function on_key_press() {
if (event.keyCode == "27") this.close();
IE has a different event model to other browsers - event is a property
of the global object (window.event), but for others you need to pass the
event to the function. For old Netscape, you need 'which', storing the
value in a local variable saves looking it up multiple times:

function on_key_press(e) {
var e = e || window.event;
var k = e.keyCode || e.which;
if ("27" == k) this.close();
...

and call with:

on_key_press(event);
else if (event.keyCode==43) resize(1.1);
else if (event.keyCode==45) resize(.9);
}
-->
</script>
</head>

<body onload="javascript:window_resize(self.o_img, 135, 50);"
There is no need for 'javascript:'. Again, self.o_img fails in Firefox,
use:

<body onload="window_resize(document.images['o_img'], 135, 50);"
onkeypress="on_key_press();">
onkeypress="on_key_press(event);">

<table id="table_all" height="100%" width="100%" border="0"
cellpadding="0" cellspacing="0">
<tr>
<td>
<table width="100%" border="0" cellpadding="0"
cellspacing="0">
<tr>
<td>
<div align="left"><nobr>
'nobr' is not a valid element (unless you use a different DTD to that
specified in your DOCTYPE):

<URL:http://www.cs.tut.fi/~jkorpela/html/nobr.html>
<img src="assets/magnify_plus.gif" style="cursor:hand"
onclick="javascript:resize(1.1);" WIDTH="107" HEIGHT="24">
All your onclick attributes don't need 'javascript:'.
<img src="assets/magnify_minus.gif" style="cursor:hand"
use "cursor: pointer;"

onclick="javascript:resize(.9);" WIDTH="117" HEIGHT="24">
<a style="cursor:hand" onClick="window.print();"><img
src="assets/print.gif" width="89" height="24" border="0"></a>

</nobr></div></td>
</tr>
</table>
</td>
</tr>
<tr height="1">
<td bgcolor="#DDDECC"><img SRC="assets/spacer_trans.gif"
width="1"
height="1"></td>
</tr>
<tr>
<td align="center" valign="middle">
<img src="assets/plot239/dev239.jpg" name="o_img" width="390"
height="310" hspace="5" vspace="5" border="0" align="top" id="o_img">
hspace, vspace, etc. are depreciated, use styles instead.

</td>
</tr>
</table>
</body>
</html>

--
Rob
Oct 14 '05 #2
Rob.. you are a diamond !!!

It worked beautifully.

Thank you ever so much.

Oct 14 '05 #3
RobG wrote:
niconedz wrote:
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<title>Aphrodite Hills</title>
<style type="text/css">
<!--
**SNIPPED**
-->
</style>
For the sake of posting sample code, just ditch the style element
completely. Using HTML comment tags inside a style element may cause
problems of itself.


No, they should not cause any problems in _HTML_ (and have none caused
with me to date). First, they are not "HTML comment tags" but empty SGML
declarations (delimited by "<!" and ">") containing only SGML comments
(delimited by "--"). Second, all CSS specifications to date and the
most recent Working Draft specify them to be allowed and to be ignored
if present, see

- CSS1, section 1.1
<http://www.w3.org/TR/CSS1#containment-in-html>

- CSS2, section D.2
<http://www.w3.org/TR/CSS2/grammar.html#q2>

- CSS2.1 (CR gone WD as of 13 June 2005), section G.2
<http://www.w3.org/TR/CSS21/grammar.html#q2>
<script language="JavaScript">


The language attribute is depreciated, type is required: [...]


The word you were looking for is "deprecated", otherwise you are correct.
function SymError()
{
return true;

}

window.onerror = SymError;


Right here you destroy your chance to see the error messages that might
help you - it stops anything useful going to the Firefox script console.

<URL:http://www.mozilla.org/docs/dom/domref/dom_window_ref58.html>


You are correct, however this bad code originates from Norton
In(ternet)Security by $ymantec. It's better to uninstall
much-too-expensive nonsense such as "Desktop Firewalls" and learn
how to use system resources to protect themselves instead (e.g. by
disabling/uninstalling unnessary networking services instead of
introducing new ones).
[...]
I guess strictly you should also test for getElementById and offer
document.all if it is not available, but that is only really necessary
if you want to support IE 4.


.... or IE < 5.5 on Windows CE (according to MSDN Library).
PointedEars
Oct 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: pantagruel | last post by:
The following does not work in firefox: <script defer="defer"> var x=document.getElementsByName("repositoryNamespace") alert(x.length + " elements!")
5
by: Mark Szlazak | last post by:
Apparently there is a textarea onscroll event bubbling bug in Firefox and Mozilla: https://bugzilla.mozilla.org/show_bug.cgi?id=229089 I'm trying to check for this bug with the following...
23
by: Loony | last post by:
I have got a code like this in HTML section in ASP file which includes javascript file! The script works under MS IE but doesn't with Firefox! Can anybody tell me what is wrong? <HTML>...
7
by: cjl | last post by:
Hey all: I've searched the newsgroup, and googled, but I'm stuck. I want to be able to 'dynamically' add a .js file to a web page after the page has loaded, based on user interaction. For...
17
by: PJ | last post by:
Greetings... I have stumbled upon a small problem. I use Ajax to retrieve part of a page I need to update. I update a DIV element with the HTML contents I get from another page. It works...
15
by: Lennart | last post by:
Hi folks, I have created an animated image gallery in dhtml. It works fine in Internet Explorer. In Firefox, it only works if I ommit the DOCTYPE tag. The page is valid xhtml-strict but with a...
5
by: gray_slp | last post by:
I am designing a web survey using surveymonkey.com and discovered I could use javascript to modify their standard question formats much the same as can be done in myspace. I used this feature to...
1
by: tinnews | last post by:
I'm running a python script via the apache ExtFilterDefine directive, it works basically as expected *except* that when I change the script apache/firefox continue to run the old version of the...
7
by: mike57 | last post by:
The minimal AJAX script below works in Firefox, but not in IE, Opera, or Chrome. I could use some suggestions or referrals to resources that will help me get the script working in other browsers. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.