www.webdeveloper.com
Results 1 to 5 of 5

Thread: Problems with "onload" and XHTML Validation

  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

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.17019 seconds
  • Memory Usage 2,894KB
  • Queries Executed 13 (?)
More Information
Template Usage (33):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_html
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (5)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (71):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates