Although it works when used without AJAX and while the page is loading, that's not very good javascript. That's almost a separate issue, except that it impacts your question to a degree.
I used this ajaxfiles/hHello.js file (not how I would write it, just made serviceable for these purposes):
Code:
function getgreeting(){
var dDay = new Date()
var nHours = dDay.getHours()
if ((nHours <12 ) && (nHours >=6)){
var hHello = ("Goodmorning !") }
if ((nHours >=12) && (nHours <18)) {
var hHello = ("Goodafternoon !") }
if ((nHours >=18) && (nHours <24)) {
var hHello = ("Goodevening !") }
if ((nHours >=0) && (nHours <6)){
var hHello = ("Goodnight !") }
return hHello;
}
and this and only this in my ajaxfiles/hello.htm page (which is how external pages should look, no extraneous tags other than a single containing div):
HTML Code:
<div>
<div id="externalhello">Hello I say: </div>
</div>
On the top page I put this (addition highlighted):
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Ajax Rotating Includes Script</title>
<script type="text/javascript" src="ajaxfiles/hHello.js"></script>
<script type="text/javascript">
/***********************************************
* Dynamic Ajax Content- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at . . .
And my link on that page is:
HTML Code:
<a href="javascript:ajaxpage('ajaxfiles/hello.htm', 'rightcolumn');">Hello</a>
Finally, in my loadpage function:
Code:
function loadpage(page_request, containerid){
if (page_request.readyState == 4 && (page_request.status==200 || window.location.href.indexOf("http")==-1))
{
document.getElementById(containerid).innerHTML=page_request.responseText
if(document.getElementById('externalhello'))
{
document.getElementById('externalhello').firstChild.nodeValue += getgreeting();
}
}
}
By no means ideal, but certainly workable and illustrates in a basic sort of way the sort of thing that's generally done in such situations.
Bookmarks