Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jul 2008
    Location
    UK
    Posts
    116
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Back button works in IE7 but not FF 3.01

    The problem that I'm having is with a back button on my page that uses JavaScript to go back through a browsers history it works fine with IE but doesn't in FF (first time i thought I say that). What happens in FF is it tries to load the previous page but then something overrides it. heres my code
    Code:
    function backUp()
    {
    if(getValue())
    {
    history.go(-2);
    }
    else
    {
    history.go(-1);
    }
    }
    The getValue is a variable im using in a search function to find a specific page
    Last edited by AmmO; 07-30-2008 at 09:40 AM.

  • #2
    Regular Coder
    Join Date
    Jul 2008
    Location
    UK
    Posts
    116
    Thanks
    4
    Thanked 0 Times in 0 Posts
    oh and if i didn't mention it im new to javascript and a intermediate html/css user

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,983
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    Try this:-

    Code:
    function backUp() {
    if(getValue()) {
    history.go(-2);
    return false;
    }
    else {
    history.go(-1);
    return false;
    }
    }
    or

    Code:
    <a href="javascript:void(0);" onclick="history.back(); return false;">Back</a>

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    Last edited by Philip M; 07-30-2008 at 09:56 AM.

  • #4
    Regular Coder
    Join Date
    Jul 2008
    Location
    UK
    Posts
    116
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Nope that didn't solve it FF still wont go back but it works fine with IE

  • #5
    Regular Coder
    Join Date
    Jul 2008
    Location
    UK
    Posts
    116
    Thanks
    4
    Thanked 0 Times in 0 Posts
    heres how im calling the scipt for my button
    Code:
    <span class="home" onclick="backUp()"><a href="#">Back</a></span>

  • #6
    Regular Coder
    Join Date
    Jul 2008
    Location
    UK
    Posts
    116
    Thanks
    4
    Thanked 0 Times in 0 Posts
    problem solved found that it was how the java scrip was being called not my original script

    Code:
    <span class="home" onclick="backUp()"><a href="#">Back</a></span>
    The problem was when you clicked on the back button it was using going to the href link before the JavaScript could be called.

    The functioning code looks like this
    Code:
    <span class="home" onclick="backUp()"><a href="javascript: backUp();">Back</a></span>

  • #7
    Regular Coder
    Join Date
    Jul 2008
    Location
    UK
    Posts
    116
    Thanks
    4
    Thanked 0 Times in 0 Posts
    alteration to the code the last one was jumping back 2 pages because it was being called twice

    Code:
    <span class="home"><a href="javascript: backUp();">Back</a></span>
    this is the fully functioning script. Lucky for me our lead coder made it back into work or i dont think id have cracked this myself

  • #8
    New Coder
    Join Date
    Jul 2008
    Location
    Peterborough - UK
    Posts
    63
    Thanks
    4
    Thanked 9 Times in 9 Posts
    *flex*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •