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 January 12th, 2004, 03:49 AM
Registered User
 
Join Date: Jan 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to prem52k Send a message via Yahoo to prem52k
Default [JS] The onLoad doesn`t trigger !

Hi All !
This is my first post here.....!
you see as the title mentions... I have two functions that has to respond as soon as the page loads..Picture a scenario that has the following code.
Code:
function siteMsg() {
  window.alert("hello");
}

function pop() {
  window.open('http://www.google.com','newWindow');
}

function all() {
  siteMsg();
  pop();
}

<body onLoad="all()">
bla bla
</body>
if i`m not mistaken this should work perfectly ok...right ?
well it doesn`t, nothing triggers...Does anyone know why, such situations happen ?
thank you.
:)

- Quitters Never Win -
 
Old January 12th, 2004, 05:48 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Works fine for me, have you got all code etc. in corect tags?
Code:
<html>
<head>
<title>Onload Test</title>
<script type="text/javascript">
  function siteMsg() {
  window.alert("hello");
}

function pop() {
  window.open('http://www.google.com','newWindow');
}

function all() {
  siteMsg();
  pop();
}  
</script>
</head>
<body onLoad="all()">
bla bla
</body>
</html>

--

Joe
 
Old January 12th, 2004, 06:01 AM
Registered User
 
Join Date: Jan 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to prem52k Send a message via Yahoo to prem52k
Default

Hi !
I found the problem. The glitch was in the onLoad itself...
I was not supposed to use more than one onLoad funtion in a script...
(sorry i haven`t mentioned that i`ve posted only a strip-down version of the source above) I found a anothe 'window.onLoad' in the page, got them sorted !
thanx :)

- Quitters Never Win - Winners Never Quit -
 
Old January 12th, 2004, 11:18 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

You can put as many things in the onLoad as you want, they just need to be separated by semi-colons at the end of each "line" of JS.

<body onLoad="alert('Hello');alert('World');">
 
Old January 12th, 2004, 09:32 PM
Registered User
 
Join Date: Jan 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to prem52k Send a message via Yahoo to prem52k
Default

yes true !
but you shouldn`t add any other onLoad, any where around the page source !
e.g: window.onLoad.

it will not trigger, the best way to over come this problem is to put all of them in one seprated by semi-colons !

- Quitters Never Win - Winners Never Quit -





Similar Threads
Thread Thread Starter Forum Replies Last Post
Ch 16 Try It Out doesn' t work + Fixes VictorVictor BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 3 December 12th, 2007 10:04 AM
Onload with AJAX Baco Intro Programming 0 June 11th, 2007 12:46 PM
iframe onLoad darkhalf Javascript 1 January 11th, 2006 04:42 PM
two script onLoad mateenmohd Javascript 2 December 28th, 2003 12:12 AM
Trigger a JS function on loss of focus apd8x Javascript 1 July 14th, 2003 09:00 AM





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