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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    How do I use the JavaScript set timeout function for the timed delay of text?

    I want to be able to display the whole contents of a text file containing 4 paragraphs of text, on a static web page, as soon as a video finishes playing on the page. The video is to be set to autorun as soon as the page loads in the browser.

    The text file mentioned above, is to remain hidden when the page initially loads and the video is playing. Please I need your advice about what JavaScript code to use to achieve this effect, and where to place the code in the HTML code of the web page. I am new to website design and the use of JavaScript code.

    I have seen examples of code used for the timed delay of the display of an image file, after a video has finished playing. I do not know how to apply this to the display of a text file.

    I do not want to convert the whole text file into an image file, as I feel this would negatively affect the search engine optimisation of the page, if there is no text content on the page. Thank you.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,928
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Code:
    <body onload = "setTimeout('showdiv()', 12000)">
    
    <div id = "mydiv" style="display:none"> 4 paragraphs of text here></div>
    
    <script type = "text/javascript">
    function showdiv() {
    document.getElementById("mydiv").style.display="block";
    }
    </script>
    12000 represents the number of milliseconds delay required. Here 12 seconds. Adjust to suit the actual time required to play the video.


    Quizmaster: Does the word 'tonsorial' refer to hair dressing or cross-dressing?
    Contestant: Cross-dressing.

  • #3
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Philip, thank you very much for the code that you have provided. In the code, at the part where you wrote "4 paragrahs of text>" , please do you mean that I should substitute the file name of the file containing the text to appear on the web page, for the words "4 paragrahs of text" in the JavaScript code, or do you mean that I should literally open the file containing the text to be displayed on the web page, and cut and paste the whole text content from the file, into that part of the JavaScript code on the web page?

    If I cut and pasted the whole contents of the text file, directly in to the JavaScript code, would the rich text formatting of the contents of the text file, still be retained, when the web page is published, or would I have to re-format the contents of the text file again, after cutting and pasting it into the JavaScript code?

    I am thinking of making the text file to be displayed on the web page, a PHP Include file, as the website will be a PHP site. Please let me know if this arrangement would work with the code that you have provided. Thank you.

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,928
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Javascipt cannot by itself read data from a file - you need to use AJAX or a server-side technology such as PHP (which is what you propose). You could also use SSI (Server-Side Includes) - <!--#include virtual="myfile.txt" -->


    I had assumed that the four paragraphs of text would be HTML mark-up.

  • #5
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you Philip for the last post. Please what would the final code look like, for the timed delay in calling and displaying the SSI on the web page? If there is no code for this in JavaScript, please do you know if there is any code for achieving this effect in PHP programming? Thank you.

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,928
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Code:
    <div id = "mydiv" style="display:none">
    <!--#include virtual="myfile.txt" -->
    </div>
    I showed you how to make the delay in post #2.

    You need to check that your server is configured to allow SSI commands, and that your page has an .shtml extension. Google for server-side includes such as http://bignosebird.com/ssi.shtml


    The PHP syntax is
    include (filename)
    Last edited by Philip M; 08-02-2010 at 11:38 AM.

  • Users who have thanked Philip M for this post:

    Mike1 (08-05-2010)

  • #7
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hello Philip,

    Thank you for all the information that you have provided in response to my recent posts. You have been very helpful.


  •  

    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
    •