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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jun 2007
    Posts
    805
    Thanks
    123
    Thanked 23 Times in 23 Posts

    Get content from an external file, kinda like php readfile?

    Hi guys.

    I have this script, but it does not work with the readfile("news.txt"). I guess you can't use php in javascript.

    Is there an alternative / how would I come around this issue?

    Code:
    <script language="JavaScript1.2">
    
    /*
    Cross browser marquee script 
    */
    
    
    //Specify the marquee's width (in pixels)
    var marqueewidth=330
    //Specify the marquee's height (in pixels, pertains only to NS)
    var marqueeheight=20
    //Specify the marquee's scroll speed (larger is faster)
    var speed=6
    //Specify the marquee contents
    var marqueecontents='<?php readfile("news.txt"); ?>'
    
    if (document.all)
    document.write('<marquee scrollAmount='+speed+' style="width:'+marqueewidth+'">'+marqueecontents+'</marquee>')
    
    function regenerate(){
    window.location.reload()
    }
    function regenerate2(){
    if (document.layers){
    setTimeout("window.onresize=regenerate",450)
    intializemarquee()
    }
    }
    
    function intializemarquee(){
    document.cmarquee01.document.cmarquee02.document.write('<nobr>'+marqueecontents+'</nobr>')
    document.cmarquee01.document.cmarquee02.document.close()
    thelength=document.cmarquee01.document.cmarquee02.document.width
    scrollit()
    }
    
    function scrollit(){
    if (document.cmarquee01.document.cmarquee02.left>=thelength*(-1)){
    document.cmarquee01.document.cmarquee02.left-=speed
    setTimeout("scrollit()",100)
    }
    else{
    document.cmarquee01.document.cmarquee02.left=marqueewidth
    scrollit()
    }
    }
    
    window.onload=regenerate2
    </script>
    
    
    <ilayer width=&{marqueewidth}; height=&{marqueeheight}; name="cmarquee01">
    <layer name="cmarquee02"></layer>
    </ilayer>

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,851
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    How about saving the contents inside news.js(a javascript array or something) and include it via script tag?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    CaptainB (05-06-2008)

  • #3
    Regular Coder
    Join Date
    Jun 2007
    Posts
    805
    Thanks
    123
    Thanked 23 Times in 23 Posts
    Thanks!


  •  

    Posting Permissions

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