• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

body onload() alternative

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,
Here is where i am getting stuck up. I am using portals. I need to call a javascript function from a common.js where table related scrolling code exists.
Rules for the codes mentions I shall call the code on <body onload()..
I can't use <body onload()....as in websphere portals...themes are controlled by the portal structure.

I need an alternative place to call this function from .js file. Which place does work..I tried <span...onmouseover()...it is working but happenning after page loaded and mouseover...and doesn't like this..

I want it to work on page load something as such...or is there an alternative i can use javascript equivalent calling for <body onload() ...

================================
HTML code..
<!--
<script language="JavaScript" src="<%=response.encodeURL("/script/ScrollableTable.js") %>"></script>
.............
................
<logic:notEqual name="resultsAnoorsForm" property="rowcount" value = "0">
<span onScroll = "makeScrollableTable('table1',true,150);">
<DIV style="text-align: center; overflow: auto; height: 150px; width: 100%" id="PrintArea" >

<TABLE id="table1" border="1" width="95%" bordercolor="black" align="center" cellspacing="0" cellpadding="0">
<THEAD>
<logic:equal name="action2" value="
...................
................
-->
===============================================

or is there a better way to implement table scrolling in IE6.0 ?

Thanks for your time
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I had the very same problem - ie I needed to call some javascript to make a table scrollable and could not use the body.onload because I am using AJAX to dynamically update content and the body.onload is not always called.

The thing with making tables scrollable in IE using javascript is that the executing javascript must be called only after the entire DOM model of the page is rendered and complete. IE does not like you using some DOM methods on an object it hasn't finished parsing completely.

The solution to this that worked for me is to use the little kown "defer" attribute in your javascript tag declaration. Place this after your table rendering code.

<script language="javascript" defer>
makeScrollableTable('table1',true,150);
</script>

See http://www.websiteoptimization.com/speed/tweak/defer/ for more details on the use of the "defer" attribute.

btw what table scrolling library are you using?

Hope this helps. I've spend a lot of time figuring this one out.

Regards,
Sanjiv
 
s basetti
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you both.
special thanks to sanjiv jivan.

I finally got it with this "defer: attribute.

I used this link for .js...
web page
It is free..


thanks
[ November 22, 2005: Message edited by: s basetti ]
 
Sanjiv Jivan
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad I was able to be of help. We've written an in-house js library for making tables scrollable and provides some advanced functionality like locked columns and horizontally scrollabe tables. Does this library support horizontal scrolling?
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a reason you can't use addEventListener (non-IE) and attachEvent (IE) to add your own window onload event?

I would be careful with the DEFER attribute because if the script file gets cached, you aren't guaranteed that it will load after the other required script file containing the column code.
 
Sanjiv Jivan
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In my case, I am using AJAX to selectively update content where some JavaScript needs to be executed after the new content has been rendered.

I haven't used the window.onload because there is a question of deregistration of events. Consider an app where there are ,say, 10 menu items and clicking an each displays a different table. To make a table scrollable, a javascript routine needs to be called after the content has been rendered. If I add an event to to window.onload in order to make the table scrollable, then it isn't clear who deregisters the event or even when this event should be deregistered. Clearly we don't want the events to simply accumulate and executed when they are not relevant.

With the defer'ed scriptlet, the relevant javascript to render the table can be inlined just after the table. Not sure if caching is an issue with inlined deferred javascript. It may be relevant only for external defered js references.

I'm assuming the scenario is similar for the other poster who is using portlets and one would not want events registered with window.onload by certain components to be executed when other components are refreshed.

The "defer" option with inlined javascript provides a clean self contained solution without having side effects.

Sanjiv
 
My name is Inigo Montoya, you killed my father, prepare to read a tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic