Invoking scroll method for an IFRAME object in HTML javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John L.

    Invoking scroll method for an IFRAME object in HTML javascript

    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.frame0 1.scroll(x,y)

    or possibly

    document.getEle mentById('frame 01').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.
    </IFRAME>

    Thanks in advance for any help you may be able to provide.


    John L.
  • Thomas 'PointedEars' Lahn

    #2
    Re: Invoking scroll method for an IFRAME object in HTML javascript

    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.frame0 1.scroll(x,y)
    This is a proprietary short-hand notation that you want to avoid.
    or possibly
    >
    document.getEle mentById('frame 01').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 HTMLIFrameEleme nt 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 `contentDocumen t'
    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.getEle mentById("...") ;
    o.contentDocume nt.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.getEle mentById("...") ;
    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 bugRiddenCrashP ronePieceOfJunk = (
    navigator.userA gent.indexOf('M SIE 5') != -1
    && navigator.userA gent.indexOf('M ac') != -1
    ) // Plone, register_functi on.js:16

    Comment

    Working...