Results 1 to 7 of 7

Thread: Body onload prolem!

  1. #1
    Join Date
    Mar 2005
    Location
    Mumbai,INDIA
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Body onload prolem!

    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.

  2. #2
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by sunny
    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

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,190 Times in 3,154 Posts
    Blog Entries
    12

    Default

    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/s...ead.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.

  4. #4
    Join Date
    Mar 2005
    Location
    Mumbai,INDIA
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question further problem

    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

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    28,926
    Thanks
    43
    Thanked 3,190 Times in 3,154 Posts
    Blog Entries
    12

    Default

    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:
    HTML Code:
    <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.

  6. #6
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1
    Get rid of both of them. In the body tag of your page, put this:
    HTML Code:
    <body onload="dayofweek_iframe();triviaofweek_iframe();">
    Alternatively, replace both of them with this single statement:

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

  7. #7
    Join Date
    Mar 2005
    Location
    Mumbai,INDIA
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up thanx

    thanx a lot ,your suggestions were very useful and helped me solve my problem.

Bookmarks

Posting Permissions

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