#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Posts
    29
    Rep Power
    0

    Javascript: POST with no history


    Hi, all. Assume we're writing a page called A.ASP...

    <a href="javascript:location.replace('b.asp')"> runs B.ASP in the current window, but replaces A.ASP in the history list (the Back button) with B.ASP, preventing the user from moving back to A.ASP.

    That's great. But now I'd like to do the same thing, but this time A.ASP contains a form that needs to post data to B.ASP. My goal is to do this *without creating a new window*!

    The closest I've gotten is this:

    <form method="post" action="b.asp" onsubmit="window.open('', self.name,,true);form.submit()">

    which I hoped would open the current window using a blank document, replacing a.asp in the history, then submit the form to b.asp.

    It works, except a.asp is not wiped out -- you can still go Back to it.

    Same result if you do this:

    <form method="post" action="b.asp" onsubmit="window.open('b.asp', self.name,,true);form.submit()">

    [[ Fantasy - What I really need is FORM.SUBMIT(True), where the parameter I just invented has the same meaning as the fourth parameter of window.open() !!! ]]

    Ignoring that little outburst, do you have any suggestions that can help me post a form without updating the Back history, and within my constraint of not opening a new window?

    Thanks,

    Charlie
    Last edited by cdarling; January 30th, 2003 at 07:42 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    191
    sorry, no way
  4. #3
  5. No Profile Picture
    Senior Citizen
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2001
    Location
    leftcoast
    Posts
    2,019
    Rep Power
    16
    <form action="b.asp" method="post">
    .......
    .......
    <input type="button" value="Submit" onclick="this.form.submit();window.location.replace('B.asp')">
    </form>
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Posts
    29
    Rep Power
    0
    Sorry, adios...that solution has the same problem as all the others I've tried.

    The location.replace sends B.ASP to the window, but without the POST data.

    The underlying challenge seems to be to somehow pass the HTTP request body created by submit() (which includes the POSTed data) into the location.replace function.

    I've tried every conceivable nesting, etc. but in every case I either get the location.replace to work or I get the submit() to work -- never both at the same time.

    If submit() returned the actual HTTP request body, and location.replace accepted an HTTP request body as an argument, it would be easy:

    <form action="javascript:location.replace( form.submit() )" ...

    but sadly, that's just another fantasy...

    Charlie
  8. #5
  9. No Profile Picture
    Senior Citizen
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2001
    Location
    leftcoast
    Posts
    2,019
    Rep Power
    16
    As I calculate it, the problem is...form submission by POST is completely encapsulated, unexposed anywhere in the JS API, so you can't control it beyond HTML. You can submit via get, of course, without even using a form. Unless you target some other window object, a new page (action) is loaded. So much for any remaining scripting in the original document.

    [a.asp]

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>untitled</title>
    <script type="text/javascript" language="javascript">

    if (window.name == 'replace') {
    window.name = '';
    location.replace('b.asp');
    }

    </script>
    </head>
    <body>
    a.asp
    <form action="b.htm?replace" method="post">
    <input type="text" name="testel" value="testval">
    <input type="submit">
    </form>
    </body>
    </html>

    [b.asp]

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>untitled</title>
    <script type="text/javascript" language="javascript">

    if (location.search.substring(1) == 'replace') {
    window.name = 'replace';
    history.go(-1);
    }

    </script>
    </head>
    <body>
    b.htm
    </body>
    </html>

    When b.asp loads - after the form data is posted - it checks to see if the location has the appropriate querystring, then names the window (flag) and jumps back to a.asp...which checks to see if the window has the appropriate name (it doesn't the first time through), then 'un-names' it and runs the replace method. OK, pretty kludgy. I think it works. The other possibility: embed a hidden iframe, submit to that (target="iframe_name") and run location.replace() from a.asp. Or maybe not.

IMN logo majestic logo threadwatch logo seochat tools logo