PDA

View Full Version : Body onload prolem!



sunny
03-27-2005, 12:52 PM
hi there,
I just want to know that whether i can make two scripts on a smae page work simultaneously with two different body onload events.

i am trying to put a daily tip as well as a daily fact with the 'daily iframe changer part2' script.

i have done necessary changes in their function names and their array names
but as the body loads,due to two onloads none of them gets loaded.

Any suggestions would be appreciated.

mwinter
03-27-2005, 12:57 PM
I just want to know that whether i can make two scripts on a smae page work simultaneously with two different body onload events.Of course. However, without seeing the code, we can only guess at solutions.

Mike

jscheuer1
03-27-2005, 04:57 PM
I tackled this with someone for the original version of this script. We went with a rewrite of the script to use one script to create three iframes. The scripts are not that different. So, you might get all you need from this thread:

http://www.dynamicdrive.com/forums/showthread.php?t=2047

Don't follow it step by step but, if you can see what we did, you can do it to your version as well. Otherwise, as Mike said, we need to see your page.

sunny
03-27-2005, 06:59 PM
well,
thanks i have read the instructions but my problem is still unsolved .so,
here is the real code(taken from dyanmic drive):

var iframeprops='width=950 height=20 marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no"'

//Specify 7 URLs to display inside iframe, one for each day of week
var daycontent=new Array()
daycontent[1]="monday.htm" //Monday content
daycontent[2]="tuesday.htm" //Tuesday content
daycontent[3]="wednesday.htm"
daycontent[4]="thursday.htm"
daycontent[5]="friday.htm"
daycontent[6]="saturday.htm"
daycontent[0]="sunday.htm"

//No need to edit after here
if (ie||dom)
document.write('<iframe id="dynstuff" src="" '+iframeprops+'></iframe>')

var mydate=new Date()
var mytoday=mydate.getDay()

function dayofweek_iframe(){
if (ie||dom){
var iframeobj=document.getElementById? document.getElementById("dynstuff") : document.all.dynstuff
iframeobj.src=daycontent[mytoday]
}
}

window.onload=dayofweek_iframe

</script>

AND THE CODE WHICHI HAVE MODIFIED AFTERREADING INSTRUCTIONS:

var ie1=document.all&&navigator.userAgent.indexOf("Opera")==-1
var dom1=document.getElementById&&navigator.userAgent.indexOf("Opera")==-1

//Specify IFRAME display attributes
var iframeprops1='width=950 height=20 marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no"'

//Specify 7 URLs to display inside iframe, one for each day of week
var daytrivia=new Array()
daytrivia[1]="1.htm" //Monday content
daytrivia[2]="2.htm" //Tuesday content
daytrivia[3]="3.htm"
daytrivia[4]="4.htm"
daytrivia[5]="5.htm"
daytrivia[6]="6.htm"
daytrivia[0]="7.htm"

//No need to edit after here
if (ie1||dom1)
document.write('<iframe id="triviastuff" src="" '+iframeprops1+'></iframe>')

var mydate1=new Date()
var mytoday1=mydate.getDay()

function triviaofweek_iframe(){
if (ie1||dom1){
var iframeobj1=document.getElementById? document.getElementById("triviastuff") : document.all.triviastuff
iframeobj1.src=daytrivia[mytoday]
}
}

window.onload=triviaofweek_iframe
</SCRIPT>
Initially i was getting the problem of sources of second iframe being displayed in first iframe.But now second iframe's content are bring showed correctly but first iframe is not being displayed?I have even checked the name of all .htm files.

MY homepage:http://www.angelfire.com/empire2/funnyland

WAITING FOR YOUR REPLY

jscheuer1
03-27-2005, 08:06 PM
A quick inspection looks like you modified the code correctly. You missed one important step from the volumes of advice on this subject. That is, you can't have two window.onload statements on one page. Get rid of both of them. In the body tag of your page, put this:

<body onload="dayofweek_iframe();triviaofweek_iframe();">If that doesn't take care of it, at least it should give us a better idea where to go from here, as is it will never work.

mwinter
03-27-2005, 08:10 PM
Get rid of both of them. In the body tag of your page, put this:

<body onload="dayofweek_iframe();triviaofweek_iframe();">Alternatively, replace both of them with this single statement:


window.onload = function() {
dayofweek_iframe();
triviaofweek_iframe();
};Mike

sunny
03-28-2005, 11:07 AM
thanx a lot ,your suggestions were very useful and helped me solve my problem.