Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 28th, 2006, 11:49 PM
Authorized User
 
Join Date: Feb 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to dimo414 Send a message via Yahoo to dimo414
Default window.onload with arguments.

I want to run a function when the page loads, but I don't want to declare it in the body tag.
Code:
<body onload="thisfunc();">
Instead, I'm using window.onload to process it directly in the script. Now, I know that when you call a function with window.onload, you don't use the parentheses, so that the script runs the function, instead of assigining it.

But what if you have a function with arguments? How do you call it with window.onload?

 
Old June 29th, 2006, 03:02 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

One way would be something like...
Code:
window.onload = new Function("myFunc('x', 'y', 'z');");

function myFunc(a, b, c){
    alert(a + b + c);
}
HTH,

Chris






Similar Threads
Thread Thread Starter Forum Replies Last Post
Onload with AJAX Baco Intro Programming 0 June 11th, 2007 12:46 PM
onLoad functionality NEO1976 Javascript 0 May 23rd, 2006 09:38 AM
iframe onLoad darkhalf Javascript 1 January 11th, 2006 04:42 PM
audio onLoad Larson HTML Code Clinic 2 February 21st, 2004 12:39 AM
two script onLoad mateenmohd Javascript 2 December 28th, 2003 12:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.