#1
  1. Rut row Raggy!
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2001
    Location
    Tornado Alley
    Posts
    560
    Rep Power
    30

    Question Problems w/JavaScript functions


    I created a JavaScript function called gb, which I want to use in the link on my login page after a successful login.

    Here's the code from my funciton:
    Code:
    function gb(numpages) {
        history.go(-numpages);
        window.location.reload();
    }
    The problem is that it refreshes okay, but ignores the history.go command, and tries to refresh the current page.

    I tried the following:

    <a href="gb(2)">
    <a href="javascript:gb(2);">
    <a href="javascript:gb(2)">
    <a href="javascript:gb('2');">

    Nothing works. What am I doing wrong? Thanks!
    Last edited by marron79; May 16th, 2003 at 06:36 PM.
    Matt
  2. #2
  3. No Profile Picture
    Senior Citizen
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2001
    Location
    leftcoast
    Posts
    2,019
    Rep Power
    16
    Actually, it should work in the opposite way that you've described: the history.go() is executed, but the second statement is lost, since you've tossed the document - along with its script - in the process of going back 2 pages.
  4. #3
  5. Rut row Raggy!
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2001
    Location
    Tornado Alley
    Posts
    560
    Rep Power
    30
    Originally posted by adios
    Actually, it should work in the opposite way that you've described: the history.go() is executed, but the second statement is lost, since you've tossed the document - along with its script - in the process of going back 2 pages.
    Okay, so how do I fix it? I want the link to go back to the page I was at before the login page (2 pages), and refresh that page. If the page isn't refreshed, it will say "you need to login to use this feature." Thanks.
    Matt
  6. #4
  7. No Profile Picture
    Senior Citizen
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2001
    Location
    leftcoast
    Posts
    2,019
    Rep Power
    16
    A php-based solution has problems, as explained here; and because of the statelessness (no sessions) of http, there's only so much JS can do across documents. You could use the 'spy window' approach (a tiny pop-up that calls opener.location.reload(true) after the call to history.go() and then closes itself), but I'd probably take the separate login window approach, as mentioned above.

    Maybe someone has a better idea.
  8. #5
  9. Rut row Raggy!
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2001
    Location
    Tornado Alley
    Posts
    560
    Rep Power
    30
    Originally posted by adios
    A php-based solution has problems, as explained here; and because of the statelessness (no sessions) of http, there's only so much JS can do across documents. You could use the 'spy window' approach (a tiny pop-up that calls opener.location.reload(true) after the call to history.go() and then closes itself), but I'd probably take the separate login window approach, as mentioned above.

    Maybe someone has a better idea.
    Even though you didn't suggest it in your initial reply, I decided to go with the popup thing. The more I thought about it, the more it made sense. Thanks!
    Matt

IMN logo majestic logo threadwatch logo seochat tools logo