Problem with code in Firefox, works OK in Netscape 7.1

B

bspittles

Can anyone tell me why the following script doesn't work in Firefox 1.5
(not sure about other versions) when it works fine in IE6 and Netscapes
7.1? Almost as importantly ;) can ayone tell me how to fix it?

<script language=javascript>

function showphoto(pic, player, w, h, winname) {
photowin = window.open("",winname, "menubar=no,width=" + w +
",height=" + h + ",resize=no");
photowin.document.write("<HTML><HEAD><TITLE>" + player +
"</TITLE><LINK REL=STYLESHEET TYPE='text/css'
HREF='../styles/results.css' TITLE='Style'></HEAD><BODY><img
src='../gifs/players/" + pic + "' border=0 width=100%></BODY></HTML>");
}

The function is called in the page:

<a href="javascript:eek:nClick=showphoto('109.jpg', 'My name', '262',
'373', '109win');"><img src="../gifs/camera2.gif" align=left
border=0></a>

The webpage can be viewed at
http://www.leektown.co.uk/info/penpictures.php

Many thanks,
Brian Spittles
 
T

Thomas 'PointedEars' Lahn

Can anyone tell me why the following script doesn't work in Firefox 1.5
(not sure about other versions) when it works fine in IE6 and Netscapes
7.1? Almost as importantly ;) can ayone tell me how to fix it?

<script language=javascript>

The `language' attribute is deprecated long since;
the required `type' attribute is missing.[1]
function showphoto(pic, player, w, h, winname) {
photowin = window.open("",winname, "menubar=no,width=" + w +
",height=" + h + ",resize=no");

It would appear that you have not declared `photowin'. Therefore you are
creating a property of the Global Object, or the object that comes before
that in the scope chain. Bad style, and known to be error-prone. At least
use the `var' keyword to declare that identifier in the execution context
you want it to reside. An alternative is to add it as property of the
`showphoto' Function object, as it would appear that it is only used by
that.
photowin.document.write("<HTML><HEAD><TITLE>" + player + ^
"</TITLE><LINK REL=STYLESHEET TYPE='text/css' ^^
HREF='../styles/results.css' TITLE='Style'></HEAD><BODY><img ^^
src='../gifs/players/" + pic + "' border=0 width=100%></BODY></HTML>");
^^^^^^^ ^^
Neither the generating nor the generated markup is Valid[1], and you have
forgotten

photowin.document.open();

before, and

photowin.document.close();

after that. Because of popup blockers and other conceivable side effects,
you should also do a feature test, the minimum being

if (photowin && !photowin.closed)
{
// access photowin
}
}

The function is called in the page:

<a href="javascript:eek:nClick=showphoto('109.jpg', 'My name', '262', ^^^^^^^^^^^^^^^^^^^
'373', '109win');"><img src="../gifs/camera2.gif" align=left
border=0></a>
^[1]

Utter nonsense. Read <URL:http://jibbering.com/faq/#FAQ4_24>
and search the archives about "pseudo-protocol".


PointedEars
___________
[1] <URL:http://validator.w3.org/>
 
B

bspittles

Mr Lahn,

Thank you very much for taking the trouble to reply in such detail.
Adding the

photowin.document.open();

and

photowin.document.close();

has allowed the script to complete, which was the main problem I was
having. I've also taken on board - and corrected - the "Utter
nonsense" you pointed out.

I have just one question. You've highlighted the open and closing of
some of the tags in my generated email, with the comment:

"Neither the generating nor the generated markup is Valid[1]"

I can't find anythng wrong with my generated code, and running it
through the checker at http://validator.w3.org/ didn't highlight any
problems (some others, but not with the tags). Could you explain
further what you think is wrong?

Again, many thanks,
Brian Spittles
 
T

Thomas 'PointedEars' Lahn


Since you appear to be fairly new to Usenet, you should know that it is
customary to call each other with the first name on Usenet, except as a
note of recognized misbehavior of the other person.

And Usenet being a one-to-many medium, unlike private e-mail, it is also
customary to omit direct addressing (with known exceptions), and use an
attribution line instead to indicate whose text you are referring to.
Thank you very much for taking the trouble to reply in such detail.

You are welcome.
[...] You've highlighted the open and closing of
some of the tags in my generated email, with the comment:

"Neither the generating nor the generated markup is Valid[1]"

It would have been better (because easier for you to refer, and easier
for other people to understand the reference) if you simply quoted what
you are replying to _in context_:

<URL:http://jibbering.com/faq/faq_notes/pots1.html>
I can't find anythng wrong with my generated code, and running it
through the checker at http://validator.w3.org/ didn't highlight any
problems

For example, you have not escaped the ETAGO delimiters "</" within the
`script' element, preferably with "<\/". A conforming markup parser, such
as the W3C Validator, will recognize the unescaped ETAGO as the end of the
`script' element CDATA content and regard the rest as not Valid. The W3C
Validator does show this as an error in the markup. (Maybe you have
thought you had fixed the problem by commenting out the script; however,
that is only the path back to the Dark Side; search the archives.)
(some others, but not with the tags).

You should understand that SGML-based markup consists of elements, not
tags. Elements are represented by start tag and corresponding end tag,
and content, where each of start tag, end tag, and content can be optional.

I /know/ that the W3C Validator did show problems with your markup other
than within the script data; for example, the missing `type' attribute
of the `script' element. Otherwise you would have posted something that
you did not actually use, which is a bad idea anyway.
Could you explain further what you think is wrong?

The Validator by itself cannot work on content that is generated
client-side, such as with document.write(). I /know/ that your
generated code is missing a DOCTYPE declaration, for example.

Therefore, you should copy the now-generated code into an empty text file
and validate that text file using the upload form of the Validator. Then
replace the current string argument of document.open() with the then-Valid
source code (removing newlines or, even better, use string concatenation or
joining of arrays to make it easier legible), and don't forget to escape
the ETAGOs again.


HTH

PointedEars
 
A

ASM

(e-mail address removed) a écrit :
I can't find anythng wrong with my generated code, and running it
through the checker at http://validator.w3.org/ didn't highlight any
problems (some others, but not with the tags). Could you explain
further what you think is wrong?

You can't use / in javascript text of a variable

to code
document.write("</div>");
could give an error with some browsers

you have to use :
document.write("<\/div>"); (escaped slash).
insteed

or at least :
document.write("<"+"/div>");
 
T

Thomas 'PointedEars' Lahn

Thomas said:
Therefore, you should copy the now-generated code into an empty text file
and validate that text file using the upload form of the Validator. Then
replace the current string argument of document.open() with the then-Valid
source code [...]

The argument of document.write() was meant here, of course.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,737
Latest member
Georgeengab

Latest Threads

Top