473,396 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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.
</IFRAME>

Thanks in advance for any help you may be able to provide.
John L.
Jun 27 '08 #1
1 3115
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
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: GrantS | last post by:
I am trying to convert the VB.Net code example povided by http://authors.aspalliance.com/JimRoss/Articles/MaintainScrollPos.aspx into C# (ASP.Net)without success. No errors are thrown in the VB...
1
by: Alexander | last post by:
Scroll IFrame Content to desired Position (JavaScript) ====================================== How can I scoll the content of an Ifram to a desire Position? The function should be:...
2
by: JCE | last post by:
I need to programmatically invoke an asp:Button click event from a javascript function. The page containing the script and the button is the HTML page associated with a WebUserControl-derived...
6
by: paul | last post by:
HI! How do we send a variable from an Iframe page back to its parent? I have a script that calculates the iframe's window size but I need to know how to send that value back to its parent so I...
2
by: Claus | last post by:
Hello, I have a long treeview with scrollbars. When I scroll down and press a treeview node, then the Load event fires and navigate in an iframe to another page. The problem is, that afterwards...
2
by: Merlin | last post by:
Hi there, I do have a complex problem and wonder if this is possible to solve. Following situation. I do have a page, where you do have a frame inside that page. That frame holds different...
1
by: bulldog8 | last post by:
I am working on a picture preview page ... some questions and suggestions have been incorporated already, but the 'user' (i.e. wife!) would like it to be more user friendly (if it isn't one thing,...
2
riptide2049
by: riptide2049 | last post by:
I really have a problem here. I have a code that is suppost to take the href of a link from the right class;value of a link maked toreturn false. the value is a Media file the file is sent to...
3
by: PrabodhanP | last post by:
I have CSS based mouseover scrolling for divContent embeded in my webpage.It works fine in IE,but not working in mozilla-FF. It is located at the location.....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.