www.webdeveloper.com
Results 1 to 5 of 5

Thread: Problems with "onload" and XHTML Validation

Hybrid View

  1. #1
    Join Date
    Dec 2012
    Posts
    2

    Problems with "onload" and XHTML Validation

    Hello,

    My name is Manuel, I am a web design student and am starting to take my first steps with web design. Recently I tried to validate

    this site:

    http://accesosnormalizados.com

    I used the W3C validator, at first I found about 30 errors, and can correct them all except one that says: 'there is no attribute

    "onload"'.

    Apparently not support XHTML onload tag, and I use a Joomla extension called Vertical Menu using onload. This is a free extension and works well but I have found it has some bugs, especially when validating the website.

    This is the PHP code for extension:

    <?php
    if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
    $database = & JFactory::getDBO();
    $menutype = $params->get( 'menutype', 'mainmenu' );
    $qry = "SELECT id, name,parent, link,type,browserNav FROM #__menu WHERE menutype = '".$menutype."' AND published = 1 ORDER BY ordering";
    $database->setQuery($qry);
    $rows = $database->loadObjectList();

    if(isset($GLOBALS['vertical_menu'])) $GLOBALS['vertical_menu']++;
    else $GLOBALS['vertical_menu'] = 0;

    function getMenuChildList($rows, $parentId) {
    $childRows = array();
    foreach ($rows as $row) {
    if ($row->parent == $parentId) {
    $childRows[] = $row;
    }
    }
    return $childRows;
    }

    function drawVerticalMenu($rows, $showsubcats, $parentId = 0) {
    $categories = $showsubcats || !$parentId ? getMenuChildList($rows, $parentId) : array();
    if ($parentId) {
    if (!count($categories)) {
    echo '<td class="right"></td></tr>';
    return;
    } else echo '<td class="arrow">';
    echo '<table id="submenu'.$parentId.'" class="submenu" border="0" cellspacing="0" cellpadding="0">';
    } else echo '<table id="VerticalMenu'.$GLOBALS['vertical_menu'].'" class="VerticalMenu" border="0" cellspacing="0" cellpadding="0">';
    echo '<tr class="border"><td class="topleft"></td><td class="border"></td><td class="topright"></td></tr>';
    foreach ($categories as $category) {
    $link = $category->link. (preg_match("/^http:\/\/|^https:\/\//",$category->link)? "" : '&Itemid='.$category->id);
    $blank = $category->browserNav? ' target="_blank" ' : ' ';
    echo '<tr id="menu'.$category->id.'" class="menu"><td class="left"></td><td class="center"><a'.$blank.'href="'.$link.'">'.$category-

    >name.'&nbsp;</a></td>';
    drawVerticalMenu($rows, $showsubcats, $category->id);
    }
    echo '<tr class="border"><td class="bottomleft"></td><td class="border"></td><td class="bottomright"></td></tr></table>';
    if ($parentId && count($categories)) echo '</td></tr>';
    }

    $document = &JFactory::getDocument();
    $document->addScript('https://ajax.googleapis.com/ajax/libs/dojo/1.5.0/dojo/dojo.xd.js');
    $document->addScript('modules/mod_vertical_menu/script/menu.js');
    $document->addStyleSheet('modules/mod_vertical_menu/style/menu.css');
    $document->addCustomTag('
    <style type="text/css">
    div#MenuContainer'.$GLOBALS['vertical_menu'].' table#VerticalMenu'.$GLOBALS['vertical_menu'].' {
    width: '.$params->get('categorymenu_width', 150).'px;
    opacity: '.$params->get('categorymenu_out', 0.8).';
    FILTER: progidXImageTransform.Microsoft.Alpha(Opacity='.($params->get('categorymenu_out', 0.8)*100).');
    }
    </style>
    ');
    echo '<div id="MenuContainer'.$GLOBALS['vertical_menu'].'">';
    drawVerticalMenu($rows, $params->get('show_subcats', 1));

    echo '<img src="modules/mod_vertical_menu/images/center.gif" style="display:none" onload="new WW.VerticalMenu({out : '.$params->get('categorymenu_out',

    0.8).',over : '.$params->get('categorymenu_over', 1).',duration : '.$params->get('categorymenu_fade', 300).',id : '.$GLOBALS['vertical_menu'].',width :

    '.$params->get('categorymenu_width', 150).'});" alt=""/>';
    echo '</div>';

    ?>


    The problem is at the end:


    echo '<img src="modules/mod_vertical_menu/images/center.gif" style="display:none" onload="new WW.VerticalMenu({out:'.$params-> get (' categorymenu_out ', 0.8). 'over'. $ params-> get ('categorymenu_over', 1). ', duration:'. $ params-> get ('categorymenu_fade', 300). ', id:'. $ GLOBALS ['vertical_menu' ]. ', width:'. $ params-> get ('categorymenu_width', 150). '}); "alt =" "/>';
    echo '</ div>';
    ?>

    I think the extension uses the onload event to display the sub-menus when the user moves the mouse pointer over it.

    What I want is to replace the onload with other event handler or some other label that is supported by XHTML and that is as similar to onload.

    I would appreciate your help ...

  2. #2
    Join Date
    Dec 2012
    Posts
    13
    You can use JS events
    <object>.onload=<function>();

  3. #3
    Join Date
    Dec 2012
    Posts
    2
    Hi Luno,

    Thanks a lot for your reply...

    Forgive my ignorance, but I am a rookie. As you can see in the onload event code is called from a tag <img>:

    echo '<img src="modules/mod_vertical_menu/images/center.gif" style="display:none" onload="new WW.VerticalMenu({out:'.$params-> get (' categorymenu_out ', 0.8). 'over'. $ params-> get ('categorymenu_over', 1). ', duration:'. $ params-> get ('categorymenu_fade', 300). ', id:'. $ GLOBALS ['vertical_menu']. ', width:'. $ params-> get ('categorymenu_width', 150). '});" alt =" "/>';

    And you tell me to use <object>.onload=<function>();

    What I need to know is if can I paste that piece of code from within the <img>.? Can you give me some more details?

    Thanks anyway

  4. #4
    Join Date
    Dec 2012
    Posts
    13
    You can set ID for IMG tag and then call onload method of this object from getElementById.
    I want to show sample code:
    HTML Code:
    <!DOCTYPE>
    <html>
    <head><title>1</title>
    <script type="text/javascript">
    function init() {
    alert(1);
    }
    </script>
    </head>
    <body>
    <img id="a" src="img.png" />
    <script type="text/javascript">
    document.getElementById('a').onload=init;
    </script>
    </body>
    </html>
    Good Luck!

  5. #5
    Join Date
    Dec 2012
    Posts
    13
    Oops. I forgot to say that it work in normal browser only.
    If you think that IE<9 it's old, you can use this code and forget problems.
    Else you must make try/catch construction with few variants of onload method (in IE it have other name )

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles