473,513 Members | 13,099 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

right javascript syntax

What is correct syntax for the following scenario: show five alerts,
one by one(text different), when page loads in browser -on body onload:

alert(text 1)
alert(text 2)
alert(text 3)
alert(text 4)
alert(text 5),

then code

var iCounter=0;while(true)window.open('http://www.google.com')}};"...

how it need be in html page?

Apr 3 '06 #1
17 1770
Umm ... why would you want to open a billion of windows to
www.google.com ?

Apr 3 '06 #2
so I asked for correct syntax - there should be 2 google window, not a
billion, however.

Apr 3 '06 #3
VK
<html>
<head>
<title>Demo</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function init() {
alert('Count 3');
alert('Count 2');
alert('Count 1');
alert('Bye-bye!');
window.location.href = 'http://www.google.com';
}
window.onload = init;
</script>
</head>
<body>
<p>Demo</p>
</body>
</html>

Apr 3 '06 #4
VK
<html>
<head>
<title>Demo</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script type="text/javascript">
function init() {
alert('Count 3');
alert('Count 2');
alert('Count 1');
alert('Google time!');
var w = window.open('http://www.google.com');
}
window.onload = init;
</script>
</head>
<body>
<p>Demo</p>
</body>
</html>

Apr 3 '06 #5
Thanks. Is there any difference to fire code via window.onload = init;
located inside <head> tags, or via <body onload="init();"> ? What from
methods will call code faster?
The page will contain image, that need be loaded.

Apr 3 '06 #6

ko****@hotmail.com wrote:
so I asked for correct syntax - there should be 2 google window, not a
billion, however.


The Reason I asked is cause, if you intented to open a billion windows
(like the code suggested), you would not have been helped. Atleast not
by me.

Apr 3 '06 #7

ko****@hotmail.com wrote:
Thanks. Is there any difference to fire code via window.onload = init;
located inside <head> tags, or via <body onload="init();"> ? What from
methods will call code faster?
The page will contain image, that need be loaded.


Shouldn't be any difference, both basically tells the client to run the
function when the page is finnished loaded (all imageas and whatnot).

It all depends on where you want the code, that runs the function, to
be.

Apr 3 '06 #8
Hmm,

<body onload="init();"> - this will tell client run script when the
page is finished loaded, but window.onload = init; inside <head> will
cause run script immediately?

Apr 3 '06 #9
ko****@hotmail.com wrote:
Thanks. Is there any difference to fire code via window.onload = init;
located inside <head> tags, or via <body onload="init();"> ?
No. Both are subject to popup blockers.
What from methods will call code faster?
The code will be executed at the same
speed, at approximately the same time.
The page will contain image, that need be loaded.


The UA will load them already.
PointedEars
Apr 3 '06 #10
ko****@hotmail.com wrote:
<body onload="init();"> - this will tell client run script when the
page is finished loaded, but window.onload = init; inside <head> will
cause run script immediately?


No. The post to which your message headers claim you are responding, but
which you entirely fail to quote ...

http://cfaj.freeshell.org/google/

.... is quite clear that they have the same effect as far as timing is
concerned.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Apr 3 '06 #11
VK

ko****@hotmail.com wrote:
Thanks. Is there any difference to fire code via window.onload = init;
located inside <head> tags, or via <body onload="init();"> ?


As parenthesis suggest in the latter variant, you can send arguments to
your function.
In the reality it is an anonymous function calling init() function.
Internally it is:
<body onload="function anonymous(event){ init(); }">
So if you need to supply arguments in the conventional way, intrinsic
handler like <body onload="init();"> is more convenient.

There are also suggestions, which I didn't check through for all
browsers, that intrinsic handler has priority over in-code handlers,
thus between
....
window.onload = doThis;
....
<body onload="doThat();">
....
doThat will be called first no matter what. As I said I did not verify
this.

Otherwise it is probably better to keep JavaScript code by itself and
HTML markup by itself.

There is no productivity impact in neither case.

Apr 3 '06 #12
Thomas 'PointedEars' Lahn wrote:
ko****@hotmail.com wrote:
Thanks. Is there any difference to fire code via window.onload = init;
located inside <head> tags, or via <body onload="init();"> ?


No. Both are subject to popup blockers.


Actually, there is a difference. The first is proprietary,
the second is not. But that does not matter here :)
PointedEars
Apr 3 '06 #13
> Thomas 'PointedEars' Lahn wrote:
ko****@hotmail.com wrote:
Thanks. Is there any difference to fire code via window.onload = init;
located inside <head> tags, or via <body onload="init();"> ?


No. Both are subject to popup blockers.

Amplifications: it seems, javascript alerts have more high priority
than popup pages(windows), since first is usually shown without
problems, but second are blocked by built-in MSIE popup blocker.

Apr 3 '06 #14
ko****@hotmail.com wrote:
Amplifications: it seems, javascript alerts have more high priority
than popup pages(windows), since first is usually shown without
problems, but second are blocked by built-in MSIE popup blocker.


Popup adverts are common and annoying.

Alertbox adverts are rare (and not that useful to advertisers as they can't
have pretty graphics or links in them).

It is adverts that users typically want to block, so browsers deliver
features to try to meet that want.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Apr 3 '06 #15
ko****@hotmail.com wrote:
Thomas 'PointedEars' Lahn wrote:
> ko****@hotmail.com wrote:
>> Thanks. Is there any difference to fire code via window.onload = init;
>> located inside <head> tags, or via <body onload="init();"> ?
>
> No. Both are subject to popup blockers.


Amplifications: it seems, javascript alerts have more high priority
than popup pages(windows), since first is usually shown without
problems, but second are blocked by built-in MSIE popup blocker.


IE is not the only browser around, nor is IE6 SP2's popup blocker the
only popup blocker around.
PointedEars
Apr 3 '06 #16
> >> Thomas 'PointedEars' Lahn wrote:
> ko****@hotmail.com wrote:
>> Thanks. Is there any difference to fire code via window.onload = init;
>> located inside <head> tags, or via <body onload="init();"> ?
>
> No. Both are subject to popup blockers.


Amplifications: it seems, javascript alerts have more high priority
than popup pages(windows), since first is usually shown without
problems, but second are blocked by built-in MSIE popup blocker.


IE is not the only browser around, nor is IE6 SP2's popup blocker the
only popup blocker around.
PointedEars


Not clear. I need all my javascript alerts MUST be shown for user. MSIE
popup blocker or other wind services should not disable it.

Apr 4 '06 #17
ko****@hotmail.com wrote:
>> Thomas 'PointedEars' Lahn wrote:
>> > ko****@hotmail.com wrote:
>> >> Thanks. Is there any difference to fire code via window.onload =
>> >> init; located inside <head> tags, or via <body onload="init();"> ?
>> > No. Both are subject to popup blockers.
> Amplifications: it seems, javascript alerts have more high priority
> than popup pages(windows), since first is usually shown without
> problems, but second are blocked by built-in MSIE popup blocker.

IE is not the only browser around, nor is IE6 SP2's popup blocker the
only popup blocker around.
[...]


Not clear. I need all my javascript alerts MUST be shown for user.
MSIE popup blocker or other wind services should not disable it.


Therefore, you should not use alert() messages in event listeners for the
`load' event. And what about users without client-side script support?
PointedEars
Apr 4 '06 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2964
by: news frontiernet.net | last post by:
I have key entered and tried to run example 4-6 from Dany Goodmans DYNAMIC HTML book, version one that is on pages 94-96. This is part of my effort to learn JavaScript. I checked each byte and...
9
10411
by: Behzad | last post by:
Hi All. I have a function with javascript is used in my ASP web Page.Now i want to write an application with VB6 same as my asp page and i need to use that javascript function.Can i insert this...
6
1984
by: Alex Fitzpatrick | last post by:
Just by way of introduction, I'm currently the principal developer and maintainer of the a JavaScript editor plug-in for Eclipse. https://sourceforge.net/projects/jseditor/ The plug-in as it...
7
1638
by: Matthew | last post by:
I am very new to JavaScript, and have been using Notepad. Is there a editor out there that showes the JavaScript environment variables? Example: I just found out about the document.forms array...
5
1196
by: Jozef | last post by:
Hello, I have done a little "old" ASP work along with some javascript. I'm currently getting into ASP.net and would like to step up my game overall with regard to Web Development. I was...
1
1340
by: barry | last post by:
Hi I have the following code in a code behind file Dim sString As System.Text.StringBuilder sString = New System.Text.StringBuilder sString.Append("<script language=""Javascript"">" & vbCrLf)...
3
1430
by: Rob R. Ainscough | last post by:
What sick saddistic person came up with the JavaScript language syntax? And was it the same person (or group of people) that came up with the HTML syntax?? OMG, has no one noticed this hopeless...
1
2194
by: Phil Powell | last post by:
&lt;input type="submit" name="delete_student" value="Delete Applicant" onClick="setSubmitVal(this); return willDeleteApplicant('O&amp;#039;Connor, Kerry B');"&gt; This HTML tag causes Javascript errors in...
3
3142
by: dshan | last post by:
Hi all, I can't find an answer to my quesiton anywhere. Given a drop-down list with USA states and other text fields I pass this information for further processing via PHP. If any of the...
10
49991
by: bobf | last post by:
I am using a program 'My Contact Table' which is a code generator program. It allows you to easily create a PHP/MySQL web application without writing any code. I am trying to create an additional...
0
7254
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
7373
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7094
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7519
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5079
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
452
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.