IE 6, javascript:void(0) stops the webpage loading

Discussion in 'Javascript' started by Jitendra, Dec 29, 2005.

  1. Jitendra

    Jitendra Guest

    Hi!
    I m facing a problem with 'javascript:void(0)'

    Software Environ:-
    IE: 6.0.2600.0000
    OS: Windows 2000 Professional with Service Pack 4

    Problem:-
    I have a webpage with several links (<A> tags), now i have added
    onClick and blocked HREF using 'javascript:void(0)' as below:-

    <a href="javascript:void(0)"
    onClick="some_function('pagename')">Text</a>

    Here 'some_function' is opening the 'pagename' in a new customised
    window.

    This page also contains a few images weighing 50kb. Now if I click the
    <a> links before the images are loaded fully, following happens (on my
    pc it works well but it happens when i test it online):-

    1. The new page opens in a window as required
    2. But the page loading is ABORTED and the images are not loaded.

    More:-
    This is not happening in FF 1.0.7

    Need Help!
    Jitendra, Dec 29, 2005
    #1
    1. Advertising

  2. Jitendra

    RobG Guest

    Jitendra wrote:
    > Hi!
    > I m facing a problem with 'javascript:void(0)'
    >
    > Software Environ:-
    > IE: 6.0.2600.0000
    > OS: Windows 2000 Professional with Service Pack 4
    >
    > Problem:-
    > I have a webpage with several links (<A> tags), now i have added
    > onClick and blocked HREF using 'javascript:void(0)' as below:-
    >
    > <a href="javascript:void(0)"
    > onClick="some_function('pagename')">Text</a>


    This is a known feature of IE and why the use of the javascript
    pseudo-protocol for the value of HREF attributes is actively discouraged.

    <URL:
    http://groups.google.com/group/comp...?q=IE javascript:void&rnum=3#1c07ad60e4d8fe1f
    >


    Use something like:

    <a href="serverFunction.html"
    onClick="some_function('pagename');return false;">Text</a>


    Where the href attribute allows the function to be performed on the
    server and the return false stops it being followed where JavaScript
    is enabled.


    [...]


    --
    Rob
    RobG, Dec 29, 2005
    #2
    1. Advertising

  3. Jitendra

    Guest

    RobG napisal(a):
    > Jitendra wrote:
    > > <a href="javascript:void(0)"
    > > onClick="some_function('pagename')">Text</a>

    > Use something like:
    >
    > <a href="serverFunction.html"
    > onClick="some_function('pagename');return false;">Text</a>
    >
    > Where the href attribute allows the function to be performed on the
    > server and the return false stops it being followed where JavaScript
    > is enabled.


    And if you don't have some server-based alternative, use something
    like:
    <a href="#" onClick="some_function('pagename');return false;">Text</a>
    and if the user has javascript turned off, the link will still have no
    effect except of appending "#" to the URL. Of course if you want some
    CGI fallback for js fault, then keep the 'backup link', but if it's to
    be a page that says "Sorry, you need Javascript", better if it does
    nothing instead.
    , Dec 29, 2005
    #3
  4. wrote:

    > And if you don't have some server-based alternative, use something
    > like:
    > <a href="#" onClick="some_function('pagename');return false;">Text</a>
    > and if the user has javascript turned off, the link will still have no
    > effect except of appending "#" to the URL.


    .... and making the user wonder why the link didn't work (probably after they
    wait for a couple of minutes for the "new page" to load).

    .... and shoving the user back up to the top of the page if they had scrolled
    down to get to the link.

    > Of course if you want some
    > CGI fallback for js fault, then keep the 'backup link', but if it's to
    > be a page that says "Sorry, you need Javascript", better if it does
    > nothing instead.


    I disagree. When the user expects something to happen, the system shouldn't
    silently fail on them. A server side alternative is best, but an error
    message beats nothing at all.

    Another option is to generate the link with JavaScript in the first place -
    after testing that all the needed features are available.

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
    David Dorward, Dec 29, 2005
    #4
  5. Jitendra

    jitendramr Guest

    Thanks all for a very prompt reply!

    : (

    1. Actually i m not worried about javascript blocking as Javascript is
    a prerequieist for my application. So the user is aware of this.
    2. I cant use '#' as IE will treat it as a page location and scroll up
    the page to the top.
    3. i am not using any server side at this level as this only requires
    to open another html page a new window....

    : )
    4. I can use 'href=somepage.html' (but i m doubtful of any flickering
    as we are calling 2 pages - 1 on href and 2 onClick, pls correct me)

    i ll let u know abt this....thnx again

    i have to dliver the app day after....hope it will work

    c ya
    jitendramr, Dec 29, 2005
    #5
  6. Jitendra

    RobG Guest

    jitendramr wrote:
    > Thanks all for a very prompt reply!
    >
    > : (
    >
    > 1. Actually i m not worried about javascript blocking as Javascript is
    > a prerequieist for my application. So the user is aware of this.
    > 2. I cant use '#' as IE will treat it as a page location and scroll up
    > the page to the top.


    Hence the suggestion to use - return false - in the onclick, it will
    stop the browser following the link (i.e. in this case, going to the
    top of the page).


    > 3. i am not using any server side at this level as this only requires
    > to open another html page a new window....
    >
    > : )
    > 4. I can use 'href=somepage.html' (but i m doubtful of any flickering
    > as we are calling 2 pages - 1 on href and 2 onClick, pls correct me)


    If you use return false the HREF will not be followed regardless of
    what you put in there. Just don't use javascript:void().


    [...]


    --
    Rob
    RobG, Dec 29, 2005
    #6
  7. Jitendra

    jitendramr Guest

    I see...i ll give a try...

    Thanks dear
    jitendramr, Dec 29, 2005
    #7
  8. Jitendra

    Randy Webb Guest

    RobG said the following on 12/29/2005 7:58 AM:
    > jitendramr wrote:
    >
    >> Thanks all for a very prompt reply!
    >>
    >> : (
    >>
    >> 1. Actually i m not worried about javascript blocking as Javascript is
    >> a prerequieist for my application. So the user is aware of this.
    >> 2. I cant use '#' as IE will treat it as a page location and scroll up
    >> the page to the top.

    >
    >
    > Hence the suggestion to use - return false - in the onclick, it will
    > stop the browser following the link (i.e. in this case, going to the top
    > of the page).
    >
    >
    >> 3. i am not using any server side at this level as this only requires
    >> to open another html page a new window....
    >>
    >> : )
    >> 4. I can use 'href=somepage.html' (but i m doubtful of any flickering
    >> as we are calling 2 pages - 1 on href and 2 onClick, pls correct me)

    >
    >
    > If you use return false the HREF will not be followed regardless of what
    > you put in there. Just don't use javascript:void().


    <a href="somePage.html" onclick="return openWindow('this.href')">

    function openWindow(newURL){
    ....
    return false
    }

    Then, if anything in the function errors, the normal navigation takes
    place. It is even a good practice when creating links with script. It
    allows *something* to happen even when something breaks.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
    Randy Webb, Dec 29, 2005
    #8
  9. Jitendra

    jitendramr Guest

    thnx randy
    jitendramr, Dec 30, 2005
    #9
  10. David Dorward <> wrote:

    > I disagree. When the user expects something to happen, the system shouldn't
    > silently fail on them. A server side alternative is best, but an error
    > message beats nothing at all.


    That's my personal opinion as well, but it seems that there is a trend
    (if Safari and my copy of the IE 7 beta indeed constitute a "trend")
    toward hiding script errors from users not actively searching for
    them.

    --
    Christopher Benson-Manica | I *should* know what I'm talking about - if I
    ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
    Christopher Benson-Manica, Dec 30, 2005
    #10
  11. Jitendra

    nothingrows Guest

    use <a href="javascript:;"
    onClick="some_function('pagename')">Text</a> :)
    nothingrows, Dec 30, 2005
    #11
  12. Jitendra

    Lee Guest

    nothingrows said:
    >
    >use <a href="javascript:;"
    >onClick="some_function('pagename')">Text</a> :)
    >

    No, don't.
    Read the rest of the thread.
    Lee, Dec 31, 2005
    #12
  13. Jitendra

    Randy Webb Guest

    nothingrows said the following on 12/30/2005 6:33 PM:
    > use <a href="javascript:;"
    > onClick="some_function('pagename')">Text</a> :)
    >


    And then test it in Firefox.... There is a thread not 3 or 4 days old
    where that instituted a problem in Mozilla based browsers where the
    javascript: URI caused the Javascript Console to open even when there
    were no errors.

    Now, please read this groups FAQ with regards to quoting, replying, and
    the javascript: pseudo-protocol before suggesting it's improper use.

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
    Randy Webb, Dec 31, 2005
    #13
  14. wrote :
    > RobG napisal(a):
    >
    >>Jitendra wrote:
    >>
    >>><a href="javascript:void(0)"
    >>>onClick="some_function('pagename')">Text</a>

    >>
    >>Use something like:
    >>
    >> <a href="serverFunction.html"
    >> onClick="some_function('pagename');return false;">Text</a>
    >>
    >>Where the href attribute allows the function to be performed on the
    >>server and the return false stops it being followed where JavaScript
    >>is enabled.

    >
    >
    > And if you don't have some server-based alternative, use something
    > like:
    > <a href="#" onClick="some_function('pagename');return false;">Text</a>


    Such pseudo-link is also considered bad practice.

    > and if the user has javascript turned off, the link will still have no
    > effect except of appending "#" to the URL.


    No. It does bring the page all the way up.
    What's important is to use a link when such link leads somewhere, when
    there is a real url, otherwise you're misusing links.

    Gérard
    --
    remove blah to email me
    Gérard Talbot, Dec 31, 2005
    #14
  15. Christopher Benson-Manica wrote:

    >> I disagree. When the user expects something to happen, the system
    >> shouldn't silently fail on them. A server side alternative is best, but
    >> an error message beats nothing at all.


    > That's my personal opinion as well, but it seems that there is a trend
    > (if Safari and my copy of the IE 7 beta indeed constitute a "trend")
    > toward hiding script errors from users not actively searching for
    > them.


    The trouble with browsers alerting about script errors is that they can't
    distinguish between errors that matter, and errors that don't. There are
    quite a few pages where moving the mouse over elements fires off
    onmouseover events that spew errors to the JavaScript console, and shoving
    these in the user's face would be ... unpleasant.

    There is a difference between a script author writing a sensible fail path
    in his script, and a scripting engine author displaying all the debug
    information to the average user.

    --
    David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
    Home is where the ~/.bashrc is
    David Dorward, Dec 31, 2005
    #15
    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. Ollej Reemt
    Replies:
    7
    Views:
    499
    Jack Klein
    Apr 22, 2005
  2. Stig Brautaset

    `void **' revisited: void *pop(void **root)

    Stig Brautaset, Oct 25, 2003, in forum: C Programming
    Replies:
    15
    Views:
    775
    The Real OS/2 Guy
    Oct 28, 2003
  3. Replies:
    5
    Views:
    815
    S.Tobias
    Jul 22, 2005
  4. Jammer
    Replies:
    1
    Views:
    109
    Bob Barrows
    Sep 21, 2003
  5. jitendramr
    Replies:
    1
    Views:
    123
    David Dorward
    Dec 29, 2005
Loading...

Share This Page