Preventing redirect after submit - showing result in new window

Discussion in 'HTML' started by Fernie, Nov 19, 2004.

  1. Fernie

    Fernie Guest

    I am submitting data using Javascript as follows:
    ...
    f.submit();
    f.target="_blank";

    My problem is that I don't know how to keep the original page from showing
    the cgi result. Please see the following example and you will see exactly
    what I mean:

    http://66.235.178.180/

    I would sincerely appreciate it if someone could help me so that the
    original page does not change.

    Thank you




    --

    ELKNews FREE Edition - Empower your News Reader! http://www.atozedsoftware.com
     
    Fernie, Nov 19, 2004
    #1
    1. Advertising

  2. Fernie

    rf Guest

    Fernie

    > I am submitting data using Javascript as follows:


    You shouldn't be. What is wrong with simply letting the browser submit the
    form. That is what forms are for.

    > ...
    > f.submit();
    > f.target="_blank";


    This is incorrect. See below.

    > My problem is that I don't know how to keep the original page from showing
    > the cgi result. Please see the following example and you will see exactly
    > what I mean:
    >
    > http://66.235.178.180/
    >
    > I would sincerely appreciate it if someone could help me so that the
    > original page does not change.


    Consider what happens when a viewer presss that submit button.

    Your onSubmit handler is called. This calls function sendForm which does a
    couple of things and submits the form, with f.submit(). That's right, the
    form is submitted at this point. The results of this submit will appear in
    *this* page.

    Then the sendForm changes the target of the form. Control then passes back
    to the onSubmit handler which does *not* return false. This indicates to the
    browser that the form submit should proceed. The browser submits the form
    again, this time with target="_blank". You get two hits on the server and
    two pages returned.

    Why are you doing this anyway? If your viewer has popup windows disabled
    they will never see the second window.

    If you insist on using a popup window then what is wrong with letting the
    browser submit the form normally but specify target="_blank" in the form.
    You seem to be jumping through all sorts of javascript hoops to make the
    browser do what it can do anyway :)

    The fix to your hoop is to reverse the order of the two lines above and to
    return false from the onSubmit handler.

    BTW you are using some IE specific things in there. There is a very good
    chance this page will break in other browsers.

    --
    Cheers
    Richard.
     
    rf, Nov 19, 2004
    #2
    1. Advertising

  3. Fernie

    Fernie Guest

    Richard,

    Thank you for responding and for your explanations. I played around with
    your suggestion below but I could not figure out how to implement it.

    > The fix to your hoop is to reverse the order of the two lines
    > above and to return false from the onSubmit handler.


    I've decided to take your advise and let the browser just submit the form
    the way its supposed to. I'm extremely weak with front-end stuff like html
    and javascript. I didn't realize that I'd be up for such a fight to get the
    behavior that I mentioned in my original post.

    Best Regards,

    Fernie



    --

    ELKNews FREE Edition - Empower your News Reader! http://www.atozedsoftware.com
     
    Fernie, Nov 19, 2004
    #3
    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. Nazir
    Replies:
    3
    Views:
    3,946
    Nazir
    Nov 13, 2003
  2. Mark
    Replies:
    1
    Views:
    1,794
  3. Sal
    Replies:
    1
    Views:
    1,000
  4. Michael Tan
    Replies:
    32
    Views:
    1,074
    Ara.T.Howard
    Jul 21, 2005
  5. Paul Oakfleet
    Replies:
    1
    Views:
    903
    Chris Riesbeck
    Sep 10, 2003
Loading...

Share This Page