473,473 Members | 1,825 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Auto Scroll iframe to end

1 New Member
I have an iframe that loads a .txt file on a page. The page is local and does not use any kind of server. The page automatically updates using

Expand|Select|Wrap|Line Numbers
  1. <META HTTP-EQUIV='refresh' content=3>
The problem I face is that I want the iframe to scroll to the bottom automatically once the page has reloaded. An example of my current progress is shown below

Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2. <HEAD>
  3. <TITLE>DP LOG</TITLE>
  4. <META HTTP-EQUIV='refresh' content=3>
  5. <META Http-Equiv="Cache-Control" Content="no-cache">
  6. <META Http-Equiv="Pragma" Content="no-cache">
  7. <META Http-Equiv="Expires" Content="0">
  8. </HEAD>
  9. <BODY>
  10.  
  11. <p><iframe name="DP Log_frame" src="example.txt" width="100%" height="50%" align="middle" scrolling="yes" frameboarder="1"></iframe><p>
  12.  
  13. </BODY>
  14. </HTML>
  15.  
Any help would be greatly appreciated. I have only just started using iframes so am a relative nwebe. Thanks in advance
Feb 5 '08 #1
3 28251
gits
5,390 Recognized Expert Moderator Expert
hi ...

here is an example:

first use a valid id for the frame and fix the frameborder-typo:

Expand|Select|Wrap|Line Numbers
  1. <iframe name="DP_Log_frame" src="example.txt" width="100%" height="50%" align="middle" scrolling="yes" frameborder="1"></iframe>
next we write a javascript function ... put that in the documents head:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function scroll_to_end() {
  3.     var frame = window.frames.DP_Log_frame;
  4.     var doc   = frame.document;
  5.     var node  = doc.getElementsByTagName('body')[0].lastChild;
  6.  
  7.     var y = parseInt(node.offsetTop, 10);
  8.  
  9.     frame.scrollTo(0, y);
  10. }
  11. </script>
  12.  
last step: in your iframe tag use:

Expand|Select|Wrap|Line Numbers
  1. onload="scroll_to_end();"
  2.  
kind regards
Feb 5 '08 #2
Moeffe
1 New Member
The above solution works fine with Internet Explorer 8, but not with Firefox 3.6.
Sep 26 '10 #3
gits
5,390 Recognized Expert Moderator Expert
you should check the lastChild node - it might be that:
Expand|Select|Wrap|Line Numbers
  1. var node = doc.getElementsByTagName('body')[0].lastChild;
just retrieves a node that wouldn't be valid, probably it will be a whitespace textnode or similar ... if it's not a textnode then the code will work ...

to get an elements position you might have a look here ... and adapt the code to your requirements
Sep 26 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: RJN | last post by:
Hi I'm using an iFrame to enclose another document. The iFrame width is sufficient to hold the enclosed document. When the enclosed document has more data and exceeds the height set for iFrame,...
6
by: PD | last post by:
I have a parent .Net page (http://mywebsite/project.aspx) that has an iframe (http://iframe/iframe.aspx) which are on seperate domains. I need to adjust the scrolling on the parent window due the...
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: jadeite100 | last post by:
Hi: I have an pop-up window with an Iframe that has a text box with scrolldown. The scrolldown in the popup-window does not work but the scroll-down for the iFrame works. The strange thing is I...
0
by: LudwigWrules | last post by:
I have an iframe on my site. I need the frame to display its "child" page at a specific point. I can do this by setting an anchor, but it makes the parent window go there, too. I was thinking of just...
2
by: eddwinpaz | last post by:
Hi everyone..!! i have a chat and i want all the new messages to be seen but ecause i have a css iframe i would like to auto scroll down. so i can see the new message instead of click the scroller...
1
by: pravinnweb | last post by:
can anyone tell me how to set auto height to outer div that is in green box id "gray-background" it should increase relatively to inner div "smbox" here is the css and html code it should work in...
1
by: John L. | last post by:
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: ...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.