www.webdeveloper.com
Results 1 to 10 of 10

Thread: Is there an iFrame that reads .txt files AND Scrolls to the Bottom of the page?

Hybrid View

  1. #1
    Join Date
    Sep 2011
    Posts
    8

    Is there an iFrame that reads .txt files AND Scrolls to the Bottom of the page?

    I have a website on a Shared Server at work that I'm trying to get an iFrame to view the contents of a lengthy .txt file and I need it to AUTOMATICALLY scroll to the BOTTOM of the .txt file when the webpage opens.

    I have a script that will scroll .htm files to the bottom but I can't get it to automatically Scroll a .txt file to the bottom (Best I've gotten is a button that you click which scrolls to the bottom) but I need it to Automatically do it when the page opens.

    If it matters... My .txt file is actually a .LOG written in notepad with the 1st word ".LOG" which automatically inserts the Time & Date Each time the file is opened and it opens with the Cursor Automatically at the Bottom of the page.

    If someone has a code that will scroll .txt files to the bottom, I'd Really Appreciate your help, Thanks!

  2. #2
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by polypay View Post
    I have a script that will scroll .htm files to the bottom but I can't get it to automatically Scroll a .txt file to the bottom (Best I've gotten is a button that you click which scrolls to the bottom) but I need it to Automatically do it when the page opens.
    Can you show that script that scrolls an iframe containing a text file?
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

  3. #3
    Join Date
    Sep 2011
    Posts
    8
    See the Code submitted by "coothead" on this link:
    http://www.codingforums.com/showthread.php?t=128432

  4. #4
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by polypay View Post
    See the Code submitted by "coothead" on this link:
    http://www.codingforums.com/showthread.php?t=128432
    That code is not capable of scrolling an iframe containing a pure text file, it has to be HTML.

    If you want that script to act when the page loads:
    Code:
    window.onload = divscroll;
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

  5. #5
    Join Date
    Oct 2008
    Location
    U.S.
    Posts
    726
    That code is not capable of scrolling an iframe containing a pure text file, it has to be HTML
    True, only because that code attempts to obtain the offsetHeight of an element with id of 'lorem' which is presumed to be in the iframes document:
    num=obj.contentWindow.document.getElementById('lorem').offsetHeight;
    Now, if you happen to set the src of an iframe to a .txt file, the browser injects html tags in to the iframe with the contents of the .txt file contained in a <pre> element, such as:
    <html><head></head><body><pre>*****plus the contents of the .txt file here without these stupid asterisks*****</pre></body></html>
    So then if you are using a .txt file as the iframes src, you would change the definition of the variable "num" above to:
    Code:
    num = obj.contentWindow.document.getElementsByTagName('pre')[0].offsetHeight;
    Now, are you actually wanting to use the .LOG file instead of .txt file? If so, IE throws a wrench in the handling of them, at least IE less than v9.0, will think the file should be downloaded by user manually. In IE 9 it's fine though. Not sure about other browsers, but .LOG does work in Firefox 5 as an iframes src. But probably best, if you do wish to use the .LOG file, is to relay it through a .php page if you have php installed on server. This would more or less "unify" the handling between different browsers. The php page would be simple:
    PHP Code:
    <?php
    //>getLog.php
    $filename 'log.LOG';//edit name of .LOG file appropriately
    echo '<pre>';
    print_r(file_get_contents($filename));
    echo 
    '</pre>';
    ?>
    And then the html page containing the iframe and the script to scroll it, try changing the iframes src to the name of your .LOG file if you wish, it will work in the latest browsers only, which may not be an issue for you if this is a local app for your intranet only and have control over what browser is used, else I would recommend the .php file:
    HTML Code:
    <html>
    <head>
    <title>some title</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    #container {
        width:600px;
        height:260px;
        border:3px double #999;
        margin:0 auto;
     }
    #myiframe {
        width:100%;
        height:100%;
     }
    </style>
    <script type="text/javascript">
    window.onload = function() {
        var obj = document.getElementById('myiframe');
        var pre0 = obj.contentWindow.document.getElementsByTagName('pre')[0];
        obj.contentWindow.scrollTo(0, pre0.offsetHeight);
    };
    </script>
    </head>
    <body>
    <div id="container">
    <iframe src="getLog.php" id="myiframe" frameborder="0"></iframe>
    </div>
    </body>
    </html>

  6. #6
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by astupidname View Post

    Now, if you happen to set the src of an iframe to a .txt file, the browser injects html tags in to the iframe with the contents of the .txt file contained in a <pre> element,
    That wasn't my experience. Attempting to access iframe.contentWindow threw an error.
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

  7. #7
    Join Date
    Oct 2008
    Location
    U.S.
    Posts
    726
    That wasn't my experience. Attempting to access iframe.contentWindow threw an error.
    May I inquire what browser & version, plus how were you accessing the file? It does work for me from a server (just checked in IE 7, 8 & 9, Firefox 5, Safari 5 & Chrome 14) but from local file Chrome gives fits trying to access the document and does not work from local file.

  8. #8
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by astupidname View Post
    May I inquire what browser & version, plus how were you accessing the file?
    Firefox on file:/// protocol, but does get wrapped in HTML from my localhost server.
    Where used, return should be executed unconditionally and always as the last statement in the function.

    That's my signature, it's not part of the damn post!

  9. #9
    Join Date
    Sep 2011
    Posts
    8
    I appreciate the information,
    Iíve been dealing strictly with HTML and I've just recently started playing around with Javascripts that Iíve gotten off the internet and I donít know anything about PHP. Anyway, Iíve just checked and my server does not support PHP but it does run Perl (Again I donít know anything about Perl).

    Can the Following be adjusted to allow the .LOG to Scroll to the Bottom?


    <html>
    <head>
    <script type="text/javascript">
    function scroll_to_end() {
    var frame = window.frames.Log;
    var doc = frame.document;
    var node = doc.getElementsByTagName('body')[0].lastChild;

    var y = parseInt(node.offsetTop, 10);

    frame.scrollTo(0, y);
    }
    </script>
    </head>
    <body>
    <iframe name="Log" src="log.txt" onload="scroll_to_end();" width="100%" height="100%" align="middle" scrolling="yes" </iframe>
    </body>
    </html>

    Thanks!

  10. #10
    Join Date
    Sep 2011
    Posts
    8
    It was Stated above that ".LOG does work in Firefox 5 as an iframes src"
    Our computers at Work are All defaulted for IE, However, we Do have Firefox 6 Installed on them. When people open this webpage Is there a way to get it to Open in Firefox and Not IE?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles