John L. wrote:
How do I invoke the scroll() method of a window object for a
scrollable IFRAME element in an HTML document?
I am using IE 7.0, and I thought the following would work:
document.frame01.scroll(x,y)
This is a proprietary short-hand notation that you want to avoid.
or possibly
document.getElementById('frame01').scroll(x,y)
where the javascript is embedded within an HTML document containing
the following:
<IFRAME id="frame01" src="http://wrch.com/pages/1466587.php"
scrolling="yes" style="HEIGHT : 250px; WIDTH : 300px">
No support for IFRAME tag.
The content of the `iframe' element (and other multimedia-related elements)
should provide an *alternative* for users where that feature is not
available (you see, HTML provides *built-in* means for graceful
degradation). To state merely that the feature does not work (in *wrong*
terms[1] that Joe User also is not likely to understand at all) ignores that
recommendation for no good reason. Please fix that; a hyperlink to the
frame resource, with a descriptive text content, would suffice here.
[1] There is no IFRAME tag; there is an IFRAME/iframe _element_, and there
are an <iframe ...start tag and an </iframeend tag for this element.
See also the HTML 4.01 Specification, section 3.2.1 (esp. the last
paragraph.)
</IFRAME>
Your script code cannot work because both lines would refer to the element
object implementing the HTMLIFrameElement interface (or its proprietary
counterpart; heretoafter: "the IFrame object"), not the object implementing
the Window interface (same as before; heretoafter: "the Window object").
I know of no DOM where *this object* would have a `scroll' method.
Generally, there are three ways to refer to the corresponding Window object.
All of which have been mentioned several times before here (IIRC); please do
a little research before you post next time.
A) The standards-compliant one
Per W3C DOM Level 2 HTML, the IFrame object has a `contentDocument'
property to refer to the (HTML)Document object of the view created by
the `iframe' element. Per W3C DOM Level 2 Views, the latter object
has a `defaultView' property to refer to an object implementing the
AbstractView interface which AFAIK is identical with the corresponding
Window object:
var o = document.getElementById("...");
o.contentDocument.defaultView
B) The almost standards-compliant one
Per proprietary DOMs (e.g. Gecko DOM and MSHTML DOM), the IFrame object
also has a `contentWindow' property to refer to its inner Window object
directly:
var o = document.getElementById("...");
o.contentWindow
C) The fully proprietary one
Per the (still proprietary) quasi-standard of "DOM Level 0" for
client-side scripting of HTML user agents, the object referred to
by the host-defined `window' property of the Global Object has a
`frames' property that is a collection of references to the Window
objects created by `frame' and `iframe' elements in the HTML document.
Therefore, either the `iframe' element needs to be given a name (maybe
instead of an ID), or it can only be referred to by its zero-based index
within that collection:
window.frames[...]
Approach C is, for historical reasons, currently the most compatible one, so
it can serve as a general fallback. (But, at least in the Gecko/20080404
DOM, if the element is included dynamically, the element object's `name'
property has to be set before it is appended as child node object.)
You should also feature-test the proprietary `scroll' method at runtime
before you call it.
HTH
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16