SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Addict
    Join Date
    Mar 2008
    Location
    Sterling, CO
    Posts
    275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript Back Button

    I've tried several JavaScript back buttons but I end up going back and forth between two pages. I guess because each page was the "previous page"!

    Here's what I mean:

    Click from page "A" (i.e. regular product page)
    Go to page "B" (i.e. account Login) NOTE: Back button works to go back to product page at this point,
    Go to page "C" (i.e. start an account, because they didn't login because they don't have an account yet)

    Then if they decide not to start an account and click back they go from start an account page "C" back to "B" okay. But if they click the back button on Account Login page "B" they go back to page "C" agian. Back and forth between "B" and "C".

    Understand?

    I need them to be able to progressively back up to the page "A" they were at.

    Here is the current JavaScript I'm using on page "B":

    Code:
    <a href="#" onclick="history.go(-1);return false;" class="back-link">

  2. #2
    Mouse catcher silver trophy
    Stevie D's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    5,830
    Mentioned
    110 Post(s)
    Tagged
    1 Thread(s)
    Why bother? Every browser since the year dot has had its own 'back' button, and 99.9999999% of all internet users know how it works. Recreating basic browser functionality with JavaScript is a waste of time, is fraught with problems, and only ends up complicating matters and frustrating users when it doesn't work exactly as they expect it to.

  3. #3
    SitePoint Addict
    Join Date
    Mar 2008
    Location
    Sterling, CO
    Posts
    275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah I know. But it kind of looks professional

  4. #4
    SitePoint Addict
    Join Date
    Mar 2008
    Location
    Sterling, CO
    Posts
    275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I thought of some more reasons.

    It gives the customer a feeling of security that he is not being trapped when he sees the back button.

    It enhances user experience because they don't have to move their mouse as far. haha

    ...

  5. #5
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,598
    Mentioned
    411 Post(s)
    Tagged
    6 Thread(s)
    At least make sure there's a fallback for those with JavaScript off. But I agree with Stevie that this is a waste of time and also asking for trouble. There's nothing unprofessional about the Back button, and predictable and familiar behavior is very important for customers.

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,604
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    You would need to actually generate the entire back button from JavaScript in order that those who don't have JavaScript don't feel trapped because the back button you put in the web page doesn't work.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  7. #7
    SitePoint Addict
    Join Date
    Mar 2008
    Location
    Sterling, CO
    Posts
    275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, I'm working on a Magento cart and it's not operational without javascript anyway. So a button sure isn't going to hurt it. I think most everyone trust javascript nowdays too.

  8. #8
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,598
    Mentioned
    411 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by Freejoy View Post
    it's not operational without javascript anyway.
    O dear, that's really bad practice. JS should be an extra layer to add functionality. The content / basic functionality should not depend on it.

  9. #9
    Mouse catcher silver trophy
    Stevie D's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    5,830
    Mentioned
    110 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Freejoy View Post
    Yeah I know. But it kind of looks professional
    Not when it doesn't work, it doesn't!

    I'm really not convinced it looks professional - most serious webbists disdain JavaScript back buttons, and I doubt other people will notice one way or the other. A JavaScript back link doesn't 'un-trap' them. If you're worried about people feeling trapped in a process, you should look at offering a proper Cancel button rather than fudging the issue.

    I'm passionately opposed to engendering 'learned helplessness', ie habituating people into using the wrong tool for the job because you've made it easy for them to do so, which then discourages them from learning how to use the tools properly in the first place. JavaScript widgets for going back, changing text size and printing the page are prime examples of this.

  10. #10
    SitePoint Addict
    Join Date
    Mar 2008
    Location
    Sterling, CO
    Posts
    275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ralph.m View Post
    O dear, that's really bad practice. JS should be an extra layer to add functionality. The content / basic functionality should not depend on it.

    I agree. It works without javascript only one can't checkout. I guess checking out is the main propose of a eCommerce site though. I think it the worst short coming of the Magneto cart.

  11. #11
    SitePoint Addict
    Join Date
    Mar 2008
    Location
    Sterling, CO
    Posts
    275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Stevie D View Post
    Not when it doesn't work, it doesn't!

    I'm really not convinced it looks professional - most serious webbists disdain JavaScript back buttons, and I doubt other people will notice one way or the other. A JavaScript back link doesn't 'un-trap' them. If you're worried about people feeling trapped in a process, you should look at offering a proper Cancel button rather than fudging the issue.

    I'm passionately opposed to engendering 'learned helplessness', ie habituating people into using the wrong tool for the job because you've made it easy for them to do so, which then discourages them from learning how to use the tools properly in the first place. JavaScript widgets for going back, changing text size and printing the page are prime examples of this.
    Yeah, it not professional if it doesn't work. I like the cancel button idea, but still one would want to be redirected back to the page they were viewing. I'm thinking some kind of php script might be better.

  12. #12
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,598
    Mentioned
    411 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by Freejoy View Post
    I'm thinking some kind of php script might be better.
    It's usually better to use a server-side language like PHP, because it doesn't depend on what your user's setting are to work.


Bookmarks

Posting Permissions

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