473,386 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

A general question about JS and onLoad() event

157 100+
Which scripts to include in the <head> and which to include in the <body> of an Html page?

I have a JS in the <body> of my page, it has a function which gets invoked on the onLoad() event of the body.This function is suppossed to make the <div> on my page invisible on load and it does, but as soon as the page loads in the browser.. atleast for a fraction of a second we can see that div and then it disappears, what can be done to prevent this?

Thanks in advance!
Jan 30 '07 #1
8 1609
acoder
16,027 Expert Mod 8TB
Why not make the div invisible in the first place so that there is no need to even wait for body onload to do that for you?
Jan 30 '07 #2
abctech
157 100+
Why not make the div invisible in the first place so that there is no need to even wait for body onload to do that for you?
Yes even I tried to make the <div> invisible in the first place itself by saying so in the CSS
[HTML]<style type=text/css>
#divStayTopLeft{
height:170px;
width:400px;
border:1px;
display:none;
}
</style>[/HTML]
and this was working but despite having written the code on a button’s onClick () event to make this <div> visible again it wasn’t happening,maybe the syntax is wrong or something I don’t know, really haven’t worked with CSS or <div> before

So I removed display:none from here and instead put it in document.write() as below:

Expand|Select|Wrap|Line Numbers
  1. <script>
  2. if (!document.layers)
  3. document.write('<div id="divStayTopLeft" style="position:absolute;overflow:scroll;display:none">')
  4. </script>    
Now it works properly! Thanks again for your suggestion acoder!
Jan 30 '07 #3
acoder
16,027 Expert Mod 8TB
No problem, you're welcome.

Just one thing: why are you checking if document.layers is not supported?
Jan 30 '07 #4
abctech
157 100+
No problem, you're welcome.

Just one thing: why are you checking if document.layers is not supported?
Well the script that I have in my page is taken from here
I just made one change in this script as per your earlier suggestion i.e replacing the <layer> tag with <div> and the rest of the script is as it is, but now I did remove that if condition since I dint have layers in my page.

Now the content of my <div> is a dynamic table being created by a Jsp scriplet and I wanted scrollbars and a floating effect for this table which I achieved through the above script.I am working on IE 6.0 and <div> works fine on it but I was told that IE and Netscape have different DOM specifications and older versions of Netscape may not support <div> hence I should surround it by <layer>,is that the case? I think thats the reason why they had that if condition in the script to distinguish between IE and Netscape, so should I retain it?

Do I need to put alternate code for different browsers? Well I still haven’t tested my web application on other browsers or older versions of IE so now I’m a bit worried about what works on which browser and what doesn’t?
Jan 30 '07 #5
acoder
16,027 Expert Mod 8TB
The code on that page gives support for Netscape 4 (a very old buggy browser). If you are going to have that line, you will have to include code to deal with a browser that does support layers, e.g. imagine if Netscape releases new browsers that support layers for backwards compatibility (I don't know if this is the case).

In any case, IE has the bulk of the market share, followed by Firefox. Other browsers that have some share of the market include Apple's Safari and Opera. Netscape 4 users will probably be very few (not sure how much percentage-wise).
Jan 30 '07 #6
abctech
157 100+
The code on that page gives support for Netscape 4 (a very old buggy browser). If you are going to have that line, you will have to include code to deal with a browser that does support layers, e.g. imagine if Netscape releases new browsers that support layers for backwards compatibility (I don't know if this is the case).

In any case, IE has the bulk of the market share, followed by Firefox. Other browsers that have some share of the market include Apple's Safari and Opera. Netscape 4 users will probably be very few (not sure how much percentage-wise).
Ok Thanks,I think I got my answer,its better not to bother about NS4 at the time!
Jan 30 '07 #7
r035198x
13,262 8TB
Which scripts to include in the <head> and which to include in the <body> of an Html page?

I have a JS in the <body> of my page, it has a function which gets invoked on the onLoad() event of the body.This function is suppossed to make the <div> on my page invisible on load and it does, but as soon as the page loads in the browser.. atleast for a fraction of a second we can see that div and then it disappears, what can be done to prevent this?

Thanks in advance!
About positioning of scripts. It is better to define them closest to where they are used deepending on their size. Generally scripts should be placed in such a way that code is easily readable and one can follow what is going on in the html easily. You should also consider writing scripts that are so general that you put them in a seperate file and call them in the pages that need them. This makes the html so much easier to read and modify.
Jan 30 '07 #8
abctech
157 100+
About positioning of scripts. It is better to define them closest to where they are used deepending on their size. Generally scripts should be placed in such a way that code is easily readable and one can follow what is going on in the html easily. You should also consider writing scripts that are so general that you put them in a seperate file and call them in the pages that need them. This makes the html so much easier to read and modify.
Thanks for that r0!
Jan 30 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: brian | last post by:
question about Onload function can one define more than one function for Onload ? <body Onload="function1()"> or can one define multiple functions one after another like <body Onload="f() g()...
2
by: Bender | last post by:
Hi, I am wanting to capture an onmousedown event without firing the body tags onload event. Also, if anyone could explain why this happens that would be excellent. I can't see how an...
3
by: Stuart | last post by:
I am very new to javaScript, and I am hoping someone can explain the differance between the following two browsers and how to deal with thier differant approach to firing the onLoad event. The...
2
by: stanley j Mroczek | last post by:
Every thing is on one machine, Programs and sql. Sql is up and running(can test with query analyzer). No changes where made! This was working fine. How do you track this error? What network...
4
by: Pai | last post by:
hello there, I am trying to rersize the window it works find in IE but doea not work with mozilla window.attachEvent(onload,MWSOnLoad); window.onload = function (MWSOnLoad) { alert('hello');...
10
by: berg | last post by:
I'm trying to use the onload event to load a series of urls. What I find is that the onload function is only called one time no matter how large the array. Here is the onload function. var...
3
by: Christian | last post by:
hi, what is the difference between the Page_Load() and OnLoad() event handlers. do they originate from a different point ?
7
by: AndrewMBaldwin | last post by:
I have a grid control (inherits from Placeholder) that has a few buttons on it. On this grid there is a filter form, which allows the user to filter/search the table for specific information. My...
20
by: Mark Anderson | last post by:
Hi, I have this in an external JS library: ///////////////////////// function addMyEvent(){ var obj; if(document.attachEvent) { obj = document.getElementsByTagName('img'); for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.