Closed Bug 250012 Opened 20 years ago Closed 20 years ago

JavaScript incorrect behaviour with OBJECT tag

Categories

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

Other Branch
x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: vlad.alexander, Unassigned)

References

Details

Attachments

(1 file)

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040626 Firefox/0.9.1
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040626 Firefox/0.9.1

There seems to be no way using JavaScript to determine if the browser is using
the OBJECT tag or alternate content. For example, using this construct, if the
browser does not find the object clsid, a textarea is rendered:

<object classid="clsid:abc..." id="object1" width="100%" height="400">
     <textarea name="alternate1" id="alternate1" cols="60" rows="15"></textarea>
</object>

However, in Mozilla/FireFox, it is impossible to determine this
programmatically. In IE, the following script works but fails in Mozilla/FireFox.

if (document.getElementById('object1') && document.getElementById('object1') !=
null) {
     alert('object is rendered');
} else {
     alert('textarea is rendered');
}


Reproducible: Always
Steps to Reproduce:
1. create an <object> tag with an invalid clsid
2. use JavaScript to test the existence of this <object>. For example:
alert(document.getElementById('object1'));


Actual Results:  
JavaScript returns an instance of the object even if the object is not rendered.

Expected Results:  
JavaScript should return "null".
*** Bug 250016 has been marked as a duplicate of this bug. ***
*** Bug 250013 has been marked as a duplicate of this bug. ***
Assignee: bugs → general
Severity: critical → normal
Component: JavaScript Console → DOM: HTML
Product: Firefox → Browser
QA Contact: firefox.js-console → ian
Version: unspecified → Other Branch
Could You provide testcase?
Your condition check is aparantly NOT usability check of <OBJECT> element, is 
existency check of <OBJECT> element ID'ed as "object1".

> if (document.getElementById('object1') && document.getElementById('object1') !=
null)

(1) Left document.getElementById('object1')
    => Returns DOM object for <object id="object1"> element
(2) Right document.getElementById('object1')
    => Returns DOM object for <object id="object1"> element
(3) document.getElementById('object1') && document.getElementById('object1')
    => Returns "right one" since "left one" is not converted to false
    => DOM object for <object id="object1"> is returned

See
http://devedge.netscape.com/library/manuals/2000/javascript/1.5/reference/ops.html#1044813
> &&   expr1 && expr2
> (Logical AND) Returns expr1 if it can be converted to false;
> otherwise, returns expr2. Thus, when used with Boolean values,
> && returns true if both operands are true; otherwise, returns false.

(4) if( document.getElementById('object1')&&document.getElementById('object1') )
    => Returns "true" since DOM object for <object id="object1"> exists
(5) if( conditions ) != null
    => Returns "true" since "true" is aparantly not "null"

I guess that IE has different DOM/JavaScript implementation.
 - When element of <object> tag is not usable due to invalid clsid or  
   something else, JSCRIPT of IE returns null object for <object> element.
(Please note that IE is not W3C complient.)
Can you check the object data on both IE and Firefox?
 var obj = document.getElementById('object1');
 alert((typeof obj)); alert(obj); alert(obj.nodeType); alert(obj.nodeName); etc.
How about when obj is "alternate1"?

Anyway, I believe this bug is INVALID.
Correction on (4) and (5)

(4 & 5) if ( object-returned-at-step3 !=null )
    "true" since DOM object for <OBJECT ID='object1'> exists and is not "null".
    (This can not be null object.)
In IE, non-existent tags and non-rendered object tags return "null".
(In reply to comment #6)
Opera 7.51 returns [object HTMLObjectElement] for non-rendered object tag in
attachment 152605 [details] as Mozilla does.
This is true when "Identify as" is Opera, Mozilla family, and even when
"Identify as MSIE 6.0".
The HTML and DOM specs _require_ that the <object> actually be present in the
DOM in this case.  Its display behavior (not painting) does not affect its
existence in the document.

Marking invalid.  The current behavior is correct.
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago
Resolution: --- → INVALID
IE doesn't always return null, either. It's very unreliable, in fact.
Component: DOM: HTML → DOM: Core & HTML
QA Contact: ian → general
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: