Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Counting the number of lines in a file

    I have a file on my server that has a number of lines in it, depending on the number of users in the chat-room.

    What I'd like to do is to count the number of lines in this file, so that I can display it next to the Link for opening the chat-room (i.e. 0 people chatting, 27 people chatting; and {if I can be bothered being clever} 1 person chatting).

    However, I cannot find a javascript way of counting lines in a file. Any ideas?

    Iain

  • #2
    Regular Coder
    Join Date
    Oct 2004
    Posts
    168
    Thanks
    0
    Thanked 5 Times in 5 Posts
    You will need a server-side language to do that, client-side JavaScript cannot.

  • #3
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just for the sake of argument, if that's a text file which can be loaded into an iframe, it may be possible to get the line count indirectly...

    For example, this works in IE:
    Code:
    <iframe style="display:none" src="xyz.txt" onload="alert(contentWindow.document.getElementsByTagName('PRE')[0].innerHTML.match(/\n/g).length + 1)"></iframe>
    Edit: ...unless those are nothing but blank-lines, because IE strips innerHTML--if its nothing but line-breaks.
    Last edited by codegoboom; 03-07-2005 at 09:31 AM.
    *this message will self destruct in n-seconds*

  • #4
    New to the CF scene
    Join Date
    Mar 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks for the help

    It's been pointed out that JavaScript isn't really the language that I should be using, so I've kinda gone for that iFrame approach, except, the iFrame src loads a .php rather than anything else. Positioning relative to the chat room, a teeny tiny iFrame just displays "($number)".

    A bit inellegant, but never mind.

    I like the idea of alerting the parent window through an iFrame, but would that work with FireFox?

    Thanks for the help!

    Iain

  • #5
    Regular Coder
    Join Date
    Aug 2004
    Location
    codegoboom@yahoo.com
    Posts
    999
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Would it work in FF? I dunno, try it & see...
    *this message will self destruct in n-seconds*


  •  

    Posting Permissions

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