Closed Bug 9192 Opened 26 years ago Closed 26 years ago

if (document.layers) else if (document.all) stops script execution

Categories

(Core :: DOM: Core & HTML, defect, P3)

x86
Windows 95
defect

Tracking

()

VERIFIED WORKSFORME

People

(Reporter: martin.honnen, Assigned: vidur)

Details

Attachments

(1 file)

It is not possible to write backwards compatible code through object checking with the M7 build as it stops script execution when encountering the following: <SCRIPT> function ObjectCheck () { if (document.layers) { alert('nn4'); } else if (document.all) { alert('ie4/5'); } else if (document.getElementById) { alert('nn5'); } } alert('before check'); ObjectCheck(); alert('after check'); </SCRIPT> The alert before the check fires but then is silence. Please get that cleared asap as it is an essential js check used to write cross browser code.
Status: NEW → RESOLVED
Closed: 26 years ago
Resolution: --- → WORKSFORME
Hmm...works for me in the viewer. There seems to be a problem with alerts in apprunner, but that's a different bug.
I am using the viewer not the apprunner. And the alerts are just there to demonstrate that the script execution dies. I have been using the if (document.layers) { } else if (document.all) { } else if (document.getElementById) { } check in two real examples and it failed to execute my nn5 targetted code as the script seems to die when encountering the document.layers check before. Here's one of the real examples. The code for NN5 works if I take out the if (document.layers) check <HTML> <HEAD> <TITLE> </TITLE> <STYLE> </STYLE> <SCRIPT> function zoomImage (imgName, width, height) { if (document.layers) { var img = document[imgName]; if (!img.overLayer) { img.overLayer = new Layer (width); img.overLayer.left = img.x; img.overLayer.top = img.y; } img.overLayer.clip.width = width < img.width ? img.width : width; img.overLayer.clip.height = height < img.height ? img.height : height; img.overLayer.bgColor = document.bgColor; img.overLayer.document.open(); img.overLayer.document.write('<IMG NAME="' + img.name + '" SRC="' + img.src + '" WIDTH="' + width + '" HEIGHT="' + height + '">'); img.overLayer.document.close(); img.overLayer.visibility = 'show'; } else if (document.all || document.getElementById) { document[imgName].width = width; document[imgName].height = height; } } </SCRIPT> </HEAD> <BODY> <A HREF="javascript: void0 " ONCLICK="zoomImage('anImage', 200, 200); return false;">zoom(200, 200)</A> | <A HREF="javascript: void 0" ONCLICK="zoomImage('anImage', 20, 20); return false">zoom(20, 20)</A><BR> Kibology inside <BR> <BR> All for Kibology <IMG NAME="anImage" SRC="kiboInside.gif"> </BODY> </HTML>
QA Contact: gerardok → desale
Status: RESOLVED → VERIFIED
I modified the script provided by reporter as following since alert still is not working. <SCRIPT> function ObjectCheck () { if (document.layers) { document.writeln('nn4'); } else if (document.all) { document.writeln('ie4/5'); } else if (document.getElementById) { document.writeln('nn5'); } } document.writeln('before check'); document.writeln('<br>'); ObjectCheck(); document.writeln('<br>'); document.writeln('after check'); </SCRIPT> And its giving me proper results. I'm not able to reproduce the bug. The second piece of code provided by Martin [Reporter] is not working. The reson its not working is because the javascript URLs are not working properly. There is a sperate bug for it and its bug# 1646. Thanks martin for this investigation. Marking bug as verified.
I still have that bug occuring and I still think that accessing document.layers and/or document.all is stopping script execution as the three examples (first two buttons fail while last succeeds) show. I am using the viewer of the M7 win release. And I get the second example which you claim does not work because of the javascript: hrefs to work as intended if I leave out the document.layers/document.all check or put them after the document.getElementById check. The javascript: void 0 onclick hrefs are just a workaround as plain javascript: hrefs do not work. But I have numerous examples of links <a href="javascript: void 0" onclick="//some js here; return false;"> which execute as intended with M7 (and elder builds as well). So the links are not causing the problem.
Status: VERIFIED → REOPENED
Depends on: 9378
Martin you are correct. There is something wrong with document.layers and what is wrong is its returning null. Attachment you provided works for me. I mean it does not stop execution of script. So even though that attachment is working still document.layers should not return null. You might be getting this error because of that. For attachemnt you provided, all three buttons work fine for me. It does not stop script from execution. What I'm doing now is, I'm reopening this bug and putting its dependency on bug# 9378 [Which is for document.layers returning null]. I won't verify this bug untill that bug is resolved. I really appreciate your investigation. I would be really happy to hear any opinion from you if I'm wrong in this by anyway. I'll verify this bug once bug# 9378 is resolved.
Status: REOPENED → RESOLVED
Closed: 26 years ago26 years ago
Status: RESOLVED → VERIFIED
No longer depends on: 9378
Actually Martin, I talked to vidur about this bug and since we are not going to support document.layers in 5.0 and after looking at your script it seems that you are also expecting document.layers to return null. According to your script if (document.layers) { alert('nn4'); } else if (document.all) { alert('ie4/5'); } else if (document.getElementById) { alert('nn5'); } You are also expecting document.layers to return null. It is actually returning null. I tried your attachment also and for me, exection of script is occuring on all three buttons. I don't know why you are facing this error. I tried on several platforms, including win-95 which you are claiming, but it works fine everywhere. I'm going ahead and marking this bug as verified. I'll appreciate your comments.
If the attached code works for you I am not pressing it as a bug. As for document.layers returning null I expected it to return undefined though a javascript check if (object.property) does not distinguish between null and undefined. I am waiting for the next milestone release, if I still get the bug I am bugging you here again.
Not a problem martin, If you see this bug again in next milestone release, let me know.
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: