Results 1 to 3 of 3

Thread: Clashing Code

  1. #1
    Join Date
    Feb 2007
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Clashing Code

    Please read and don't be put off by the length, I'm sure the problem is quite easy to fix.

    Hey, I have clashing code and i am in need with help. It is a lot to ask but i have been trying myself for a while and i have got no where. I am sure that the fault is with onload and onunload.

    What are the codes?
    One of them sets a cookie to remember what content to hide/show
    the other code is part of a chain of codes which moves a box accross the page

    So here is the two peices of clashing code, if you want to take a look at the whole page just ask but im sure the problem is within parts shown.

    Code 1
    HTML Code:
    <script type="text/javascript">
    <!--
    function WidgetRememberCreate(name,value,days) {
      if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
      }
      else var expires = "";
      document.cookie = name+"="+value+expires+"; path=/";
    }
    
    function WidgetRememberRead(name) {
      var nameEQ = name + "=";
      var ca = document.cookie.split(';');
      for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
      }
      return null;
    }
    
    function WidgetRememberDelete(name) {
      WidgetRememberCreate(name,"",-1);
    }
    
    function hidewidget(id) {
      toggleBox1(id,'none');
      WidgetRememberCreate(id,'none');
    }
    
    function showwidget(id) {
      toggleBox1(id,'block');
      WidgetRememberCreate(id,'block');
    }
    
    function toggleBox1(id, display) {
      // DOM3 = IE5, NS6
      if (document.getElementById) {
        document.getElementById(id).style.display = display;
      // Netscape 4
      } else if (document.layers) {
        document.layers[id].display = display;
      // IE 4
      } else if (document.all) { 
        document.all[id].style.display = display;
      }
    }
    
    if(document.getElementsByTagName)
    window.onload = function nnn() {
    var divs=document.getElementsByTagName('div')
    for (var i_tem = 0; i_tem < divs.length; i_tem++)
    if(divs[i_tem].id!='' && WidgetRememberRead(divs[i_tem].id))
        toggleBox1(divs[i_tem].id,WidgetRememberRead(divs[i_tem].id));
    }
    
    // -->
    </script>
    snapshot of Code 2.
    HTML Code:
    <script type='text/javascript'>
    
    var fen = new Array(), fen_count = 4;  //check no of fens
    
    window.onload = function()
    {
      for (var i = 1; i <= fen_count; ++i) {
        fen[i] = new xfen('fen'+i, i*100, i*100, 'fenBar'+i, 'fenResBtn'+i, 'fenMaxBtn'+i);
      }
    }
    window.onunload = function()
    {
      for (var i = 1; i <= fen_count; ++i) {
        fen[i].onunload();
      }
    }
    </script>
    I know both of the codes are right because they both work on seporate pages.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Onload conflict:
    Code:
    window.onload = function nnn() {
    var divs=document.getElementsByTagName('div')
    for (var i_tem = 0; i_tem < divs.length; i_tem++)
    if(divs[i_tem].id!='' && WidgetRememberRead(divs[i_tem].id))
        toggleBox1(divs[i_tem].id,WidgetRememberRead(divs[i_tem].id));
    }
    Code:
    window.onload = function()
    {
      for (var i = 1; i <= fen_count; ++i) {
        fen[i] = new xfen('fen'+i, i*100, i*100, 'fenBar'+i, 'fenResBtn'+i, 'fenMaxBtn'+i);
      }
    }
    Remove these two and combine them into:
    Code:
    window.onload = function()
    {
      var divs=document.getElementsByTagName('div')
      for (var i_tem = 0; i_tem < divs.length; i_tem++)
      if(divs[i_tem].id!='' && WidgetRememberRead(divs[i_tem].id))
        toggleBox1(divs[i_tem].id,WidgetRememberRead(divs[i_tem].id));
    
      for (var i = 1; i <= fen_count; ++i)
        fen[i] = new xfen('fen'+i, i*100, i*100, 'fenBar'+i, 'fenResBtn'+i, 'fenMaxBtn'+i);
    }
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Feb 2007
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thank you so muych. I would give you rep but you cant on this forum

    Thanks

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
  •