...

View Full Version : How do I use the JavaScript set timeout function for the timed delay of text?



Mike1
07-29-2010, 05:22 PM
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.

Philip M
07-29-2010, 07:15 PM
<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.

Mike1
07-29-2010, 10:07 PM
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.

Philip M
07-30-2010, 08:51 AM
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.

Mike1
08-02-2010, 10:23 AM
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.

Philip M
08-02-2010, 11:20 AM
<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)

Mike1
08-20-2010, 07:32 AM
Hello Philip,

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum