right javascript syntax

Discussion in 'Javascript' started by korund@hotmail.com, Apr 3, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

  2. [on] Guest

    Umm ... why would you want to open a billion of windows to
    www.google.com ?
    [on], Apr 3, 2006
    #2
    1. Advertising

  3. Guest

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

    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, 2006
    #4
  5. [on] Guest

    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.
    [on], Apr 3, 2006
    #5
  6. [on] Guest

    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.
    [on], Apr 3, 2006
    #6
  7. Guest

    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, 2006
    #7
  8. 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
    David Dorward, Apr 3, 2006
    #8
  9. 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
    Thomas 'PointedEars' Lahn, Apr 3, 2006
    #9
  10. VK Guest

    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.
    VK, Apr 3, 2006
    #10
  11. Thomas 'PointedEars' Lahn wrote:

    > 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
    Thomas 'PointedEars' Lahn, Apr 3, 2006
    #11
  12. Guest

    > Thomas 'PointedEars' Lahn wrote:
    >
    > > 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, 2006
    #12
  13. 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
    David Dorward, Apr 3, 2006
    #13
  14. wrote:

    >> Thomas 'PointedEars' Lahn wrote:
    >> > 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
    Thomas 'PointedEars' Lahn, Apr 3, 2006
    #14
  15. Guest

    > >> Thomas 'PointedEars' Lahn wrote:
    > >> > 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, 2006
    #15
  16. wrote:

    >> >> Thomas 'PointedEars' Lahn wrote:
    >> >> > 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
    Thomas 'PointedEars' Lahn, Apr 4, 2006
    #16
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tom
    Replies:
    0
    Views:
    415
  2. =?Utf-8?B?QmlzaG95?=
    Replies:
    0
    Views:
    969
    =?Utf-8?B?QmlzaG95?=
    Dec 28, 2006
  3. Bogdan
    Replies:
    1
    Views:
    774
    Bogdan
    Jun 16, 2009
  4. Leon
    Replies:
    3
    Views:
    165
    TaeHo Yoo
    Nov 26, 2004
  5. Oran
    Replies:
    2
    Views:
    521
Loading...

Share This Page