By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,750 Members | 984 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,750 IT Pros & Developers. It's quick & easy.

body onload when page is not loaded

P: 29
I have following situation:

<body onLoad= "Init()">

my external javascript function (included in the html page):

Expand|Select|Wrap|Line Numbers
  1. function Init() {
  2.   if (CtFlgTouchScreen == true) {
  3.     var script = document.createElement("script"); 
  4.     script.type = "text/javascript"; 
  5.     script.src = "../js/vkb/keyboard.js";
  6.     document.getElementsByTagName("head")[0].appendChild(script); 
  7.     VKBInput();
  8.     VKBTextArea();
  9.     }
  10. // ALERT
  11. }
this function is called before the total page is loaded.

solution 1:
add for example an alert box where you see "// ALERT", the scripts are not activated in the page. (a bad solution ofcourse)

solution 2:
i can add following line on the BOTTOM of the page:
<script language="javascript">Init()</script>
I don't like this way around.

solution 3:

add "window.onload" in the function.
this don't work. I added it at the end of the function.

Nov 3 '08 #1
Share this Question
Share on Google+
7 Replies

P: 583
...this function is called before the total page is loaded....
Not necessarily, according to this page the onLoad is triggered when the page is fully loaded.

The browser triggers onLoad when the document is finished loading. The contents of onLoad is one or more JavaScript commands. So, for example, this <BODY ...> tag tells the browser to bring up an alert box once the page is completely loaded:
But I don't think this occurs to plug-ins, like adobe flash player, etc...

Nov 3 '08 #2

P: 29
still it doesn't seem this way.
maybe because i use includes to add external javascripts.

with the script at the bottom of the page it works.
with the onload function it doesn't work.

when i don't add the script below the page, nor i add it in the onload event of the body tag, i can use following:

window.onload = function Init() {

still, if I don't add an alert command at the end of the function, the script wouldn't run correctly.
Nov 3 '08 #3

P: 29
If I run my page locally, everything works fine.
if I run it on my webserver, the script is not runned

I don't understand it at all...
Nov 3 '08 #4

Expert Mod 5K+
P: 5,389
i guess this will have something to do with those 2 VKBxxxx-functions ... what do they do? an alert just breaks the 'flow' of the js-code-execution, its kind of a modal message - and 'time critical' or not correctly synchronized code like ajax-calls or something like this will work ... since the async calls have more time to get ready. is anything loaded with the mentioned functions? ...

kind regards
Nov 3 '08 #5

rnd me
Expert 100+
P: 427
you can't refer to the code in an external script before it loads.

move those two function calls gits mentioned to keyboard.js, and the problem should go away.

-or add your onload in keyboard.js.

-or add the external script tag synchronously by document.writing the external script tag instead of dom adding it.
Nov 4 '08 #6

P: 29
i didn't replied on this topic.
but to inform people who search this forum and have similar problems,
this is the solution:

-or add the external script tag synchronously by document.writing the external script tag instead of dom adding it.

thanks again
Dec 11 '08 #7

rnd me
Expert 100+
P: 427
i wish everyone would come back just to say thanks...
Dec 11 '08 #8

Post your reply

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