473,387 Members | 1,534 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,387 software developers and data experts.

Auto Scroll iframe to end

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 28216
gits
5,390 Expert Mod 4TB
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
The above solution works fine with Internet Explorer 8, but not with Firefox 3.6.
Sep 26 '10 #3
gits
5,390 Expert Mod 4TB
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...

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.