Slashdot Mirror


Ajax Back, Forward, Reload and PHP

IdaAshley writes "A major challenge of Asynchronous JavaScript and XML (Ajax)-driven Web sites is the lack of a Back button. Mike Brittain discusses ways to get around this obstacle in part 1 of the 'Developing PHP the Ajax way' series." From the article: "The Web is a page-by-page medium. The backward and forward buttons on your browser's toolbar direct the browser from page to page. When Macromedia's Flash became all of the rage, developers and users started to see how Rich Internet Applications (RIAs) break this metaphor. You might click around a few sites, land on a Flash-based Web site, then click around in it for a few minutes. One click of the Back button and the ride is over. Rather than going one step backward within the Flash site, you completely lose your place."

52 comments

  1. Stupid by 19thNervousBreakdown · · Score: 2, Insightful

    This is terrible, and does nothing to make the back button in the browser work. At best, it gives you an undo/redo in the applications. The back button not working is more of a symptom than the actual problem, and if widely implemented this kind of workaround is only going to distract and make it less likely that the actual problem get fixed.

    --
    <xml><I><am><so><damn>Web 2.0</damn></so></am></I></xml>
    1. Re:Stupid by SiggyTheViking · · Score: 1

      I think that is the best sig I have seen this week.

      Cheers,

      Siggy

  2. Non-news by suv4x4 · · Score: 4, Insightful

    That has been discussed to death and known for years. You do it with a hidden iframe and anchor links (#blahblah). That's the gut of the whole deal.

    1. Re:Non-news by Schraegstrichpunkt · · Score: 2, Informative

      No. That would be the correct way to do this, but it looks as though the article tells you how to make your own set of alternative history buttons. Ugh.

  3. Re:The old Slashdot... by Mydron · · Score: 3, Informative

    I felt the same way. I recommend you install the Stylish firefox extension and specify the following CSS modifications (also removes left hand nav bar):

    @-moz-document domain(slashdot.org) {
    body {
        font: 82%/150% Times !important;
    }

    #contents { margin-left: 0em !important;}
    div#links{display:none !important;}
    }

  4. To put it simply by Kesch · · Score: 4, Informative

    All it does is create a history stack then store it as a cookie. The history is then used to power the back button in whatever the application is.

    What'll intrigue me is when someone comes up with a way to integrate the back functions of ajax and friendsto work seamlessly with the browser back button. Hmm... someone should do a Firefox extension.

    The hardest part would be deciding on a standard API for this.

    --
    If this signature is witty enough, maybe somebody will like me.
    1. Re:To put it simply by RingDev · · Score: 4, Interesting

      My thought would be to set the index page up to read that history stack cookie and redirect the browser to a live page. That way, if the user hit's the back button, they get kicked back to the index page. The index page slices the top item off the stack and redirects the user to the live page with the top item on the history stack as the target.

      Not a FF plug in, but it would be a seamless solution to the back button issue for a website.

      -Rick

      --
      "Most people in the U.S. wouldn't know they live in a tyrannical state if it walked up and grabbed their junk." - MyFirs
    2. Re:To put it simply by Anonymous Coward · · Score: 0

      that wouldn't work. If a page redirects, it isn't added to the browser history.

    3. Re:To put it simply by RingDev · · Score: 1

      There are ways of redirecting a page and retaining the history.

      -Rick

      --
      "Most people in the U.S. wouldn't know they live in a tyrannical state if it walked up and grabbed their junk." - MyFirs
  5. Re:The old Slashdot... by Anonymous Coward · · Score: 0

    Why would you need the Stylish extension when all of those CSS rules could be enclosed in the @-moz-document domain() directive? They'll still only take effect at Slashdot.

  6. browsers could support client-specified urls by radarsat1 · · Score: 1, Insightful

    When you browse Google Maps for example, there is a button called "Link to this page". It's needed because the URL in the address bar doesn't actually allow you to browse to the map you are viewing. This is because google has no way of dynamically specifying the "link" URL in your address bar without making your browser go to another page.

    (Like when you change location.url -- it makes your browser actually go there, not just display different text in the address bar.)

    Something like "Link to this page" could be implemented as a standard, so that when you're viewing an AJAX site, the "bookmark" button could be given a special URL that would actually go back to that page as intended, which the AJAX application would have to be programmed to support. The link that is actually bookmarked might differ from the one you used to get to what you are viewing, but is guaranteed to get you back there if you click it.

    On the other hand, a system like that would also be very ripe for phishing exploits, so never mind.

    1. Re:browsers could support client-specified urls by levell · · Score: 3, Informative

      As other people have pointed out in other threads you can have working bookmarks without changing the window.location, using anchors. The site in my sig uses a primitive implementation but still needs a lot of work.

      --
      Struggling to find a day everyone can make? WhenShallWe.com
  7. Time to drag out this old chestnut: by This+Old+Chestnut · · Score: 0, Offtopic

    "Every great mistake has a halfway moment, a split second when it can be recalled and perhaps remedied. That split second is now."

    -- Perl Buck, 1843

    1. Re:Time to drag out this old chestnut: by mph · · Score: 1
      Perl Buck, 1843
      It may be an old chestnut, but it's not that old! (And it's not widely known that, like Ada Lovelace, Ms. Buck would later give her name to a programming language.)
  8. How about: by llamalicious · · Score: 3, Interesting

    How about doing something that actually uses the built-in back and forward buttons of the browser (when possible)?

    Like something similar to this?

  9. Tools that Support This by MikeyTheK · · Score: 5, Insightful

    We already know that Morfik and GWT support all of these features, but does Script# or Atlas, yet? I didn't think so, but my memory may be faulty. Even more importantly than knowing how to support is not having to know how to support it. Thankfully AJAX is advancing so quickly that articles like this are going to be less and less relevant since more and more tools will just implement the features right out of the box.

    --
    Friends help you move. Real friends help you move bodies.
    Never forget: 2 + 2 = 5 for extremely large values of 2.
  10. Already been integrated into browser by dFaust · · Score: 4, Insightful

    I'm 99.5% positive that Adobe Flex can help address using back/forward buttons in the browser and Google has code to do this with Ajax. If I'm not mistaken, Gmail no longer croaks if you try using back/forward now. I'm at work and don't want to take the time to look up the links, so (hopefully) free mod points to whoever feels like posting some links to this stuff!!

    That being said, the article is garbage. People ARE integrating it into the browser controls... no point in using this crappy method. Fact is, most users will, through force of habit, use the back/forward buttons, or mouse gestures, or keyboard shortcuts.

    1. Re:Already been integrated into browser by md17 · · Score: 3, Informative

      You are right about Flex already doing this. Want proof? Go to http://maps.yahoo.com/beta
      Enter an address and hit enter, repeat n times, now use your browser back & forward buttons at will. :)
      Flex has been doing this for a few years and many components support integration with the history manager out-of-the-box. More info here:
      http://livedocs.macromedia.com/labs/1/flex20beta3/ 00000996.html

      BTW: Flex 2 SDK is now free as in beer: http://labs.adobe.com/wiki/index.php/Flex:SDK_Anno uncement

      Disclaimer: I work for Adobe.

    2. Re:Already been integrated into browser by dFaust · · Score: 3, Informative

      Someone already responded with Flex info, but here's the Google link:
      http://code.google.com/webtoolkit/

      Under "Browser History Management" - "No, AJAX applications don't need to break the browser's back button."

      And I'm sure Google's GWT ain't the only library in town to do this...

  11. Doesn't use the browser's back/forward by tedhiltonhead · · Score: 2, Interesting

    This doesn't talk about using the browser's native back/forward buttons, as I inferred from the summary. It just creates fake back/forward buttons within the application, and maintains a history stack. Move along, nothing to see here...

  12. Back Button Not a Problem by mattwarden · · Score: 5, Insightful

    A major challenge of Asynchronous JavaScript and XML (Ajax)-driven Web sites is the lack of a Back button

    So says you. I say: if it makes sense for a user to hit your back button, why are you using Ajax? Do users hit their back button when they're using native desktop applications? Sounds to me like you're just to ajax-ify a traditional web application for the heluvit.

    1. Re:Back Button Not a Problem by belg4mit · · Score: 1

      It certainly makes sense to be able to drag, zoom etc. within a mapping app (e.g; google maps)
      and it certainly makes sense to be able to go back to your previous viewing extent too.

      --
      Were that I say, pancakes?
    2. Re:Back Button Not a Problem by mattwarden · · Score: 1

      The map example is always the gray area, and I'll admit that it does make some amount of sense (however, somehow desktop map applications seem to pull it off without a back button). Other than maps, though, are there any other examples?

    3. Re:Back Button Not a Problem by belg4mit · · Score: 3, Insightful

      Well, no decent GIS application lacks a back button.

      I don't track too many AJAXy sites, but I should think anything where you can have a significant
      change in scope of the content presented (particularly when it makes up the bulk of the page and
      there is little else in the way of controls or context) ought to allow the user to go back to a
      previous scope. Mail box to mail box, browsing a nested discussion.

      --
      Were that I say, pancakes?
    4. Re:Back Button Not a Problem by Anonymous Coward · · Score: 0
      I say: if it makes sense for a user to hit your back button, why are you using Ajax? Do users hit their back button when they're using native desktop applications?
      Agreed. As AJAX applications become more desktop/window like the browsers back and forward buttons become more irrelevant.

      The APhPLIX toolkit produces desktop/window style applications and includes a history object capable of handling multiple history stacks, however this functionality is for internal use by applications and it would make no sense to use the browsers back & forward buttons.
    5. Re:Back Button Not a Problem by Sloppy · · Score: 2, Insightful
      Sounds to me like you're just to ajax-ify a traditional web application for the heluvit.
      Isn't that the same reason everyone else is doing it?
      --
      As copyright owner of this comment, I authorize everyone to defeat any technological measure which limits access to it.
    6. Re:Back Button Not a Problem by Anonymous Coward · · Score: 0

      Do users hit their back button when they're using native desktop applications?

      Yes. In that context, it's called "undo".

  13. Er... already done by brunes69 · · Score: 5, Informative

    Ever use GMail? Next time you're ina folder hit your back button.

    Guess what? Works as expected.

    There's nothing magical about making the back and forward buttons work alonsgide AJAX. The way Google does it is to track a uniqke token that associates what your page state is on th ebackend, and pass the token along in an IFRAME every time you do something on the page. Since an IFRAME will work along withh your back/forward buttons, functionality is preserved.

    It isn't rocket science. Sites who don't want to do this properly are either designed by people who don't know any better, are lazy, or some combination of the two.

    1. Re:Er... already done by Richard_at_work · · Score: 1

      It depends entirely on which browser you are in as to whether it works in Gmail - IE and Firefox take you back to the previous page as expected, but Safari reloads Gmail totally (the back button takes you to the redirect page that is part of Gmails loading system).

    2. Re:Er... already done by Mozk · · Score: 1

      I'm using Firefox 1.5.0.4 with no exotic extensions, and when I press the back button, it reloads GMail.

      --
      No existe.
    3. Re:Er... already done by larry+bagina · · Score: 1

      ever use gmail with opera? the back button is completely broken.

      --
      Do you even lift?

      These aren't the 'roids you're looking for.

    4. Re:Er... already done by RedWizzard · · Score: 1

      Works for me with FF 1.5.0.4 on WinXP. Maybe you're using a security setting that stops it working?

    5. Re:Er... already done by markh100 · · Score: 1

      I'm using Firefox 1.5.0.4 as well. I have the default security settings enabled. Sometimes when I hit the back button in GMail it works, but usually, I get the following message after a 30 second delay:

      Loading...

      This seems to be taking longer than usual. Your session may have been interrupted. If your account doesn't appear in the next few seconds, please refresh this page in your browser.

      If you continue to have trouble loading your account, please visit the help center for troubleshooting information.

  14. Which one? by Dorceon · · Score: 1

    Ruby?

    --
    What sound do people on rollercoasters make? Hint: it's not Xbox 360.
    1. Re:Which one? by mph · · Score: 2, Funny

      No, C. Most people think it was named after C. Everett Koop, but they're mistaken.

  15. Absolutely correct by b0r1s · · Score: 2, Informative

    Not only does the hidden frame + named anchors work with AJAX, it also works for other browser-button-challenged technologies, like full flash sites. Case in point, one of the better known design studios (apparently does work for Ford, Motorola, AOL, Disney, Bacardi, etc) just relaunched, so click click click for working browser buttons.

    --
    Mooniacs for iOS and Android
    1. Re:Absolutely correct by Municipa · · Score: 2, Funny

      Doesn't work all that well. I navigated the site a bit and forgot all about why I was there because it's so pretty... then I remembered, tried the back and forward buttons and the problems started. Blank pages, pages with just the pretty background image and no menu/content. Inconsistencies when going back and forth multiple times. Finally I was stuck in black page mode. Music played throughout though.

    2. Re:Absolutely correct by suv4x4 · · Score: 1

      Inconsistencies when going back and forth multiple times. Finally I was stuck in black page mode. Music played throughout though.

      That's the gut of 2advanced: incredible designs, but let's say they were never the sharpest programmers in class.

  16. Implemented using #anchor links and iframes by ydnar · · Score: 1

    We implemented in-page history (and bookmarking) in Vox by overloading the anchor portion of the URI (the part after the #) and using iframes in IE. The anchor URI form is in simple key:value form that the JavaScript parses and triggers an event to enter the state specified.

    Randy

  17. Dojo by WedgeTalon · · Score: 1

    Dojo has already solved this and is also an all-around great ajax toolkit. It's major drawback is a horrible gap in documentation. If you're not afraid of mailing lists and IRC, this is easily overcome.

  18. Re:The old Slashdot... by poulbailey · · Score: 1

    Why aren't you using Georgia or one of the new Vista fonts (if you have access to those)? It seems such a waste to use a typeface that isn't designed for viewing on a screen.

  19. Alright, enough with the dead language by Anonymous Coward · · Score: 0

    PHP is a lost cause, and hopefully any decent web programmer has switched to Ruby On Rails already. If you haven't, please google for "Ruby on Rails". You'll find no bullshit coders there.

    1. Re:Alright, enough with the dead language by melonman · · Score: 1

      PHP is a lost cause... please google for "Ruby on Rails". You'll find no bullshit coders there.

      Ok, I'll bite...

      PHP is not a lost cause precisely because of your last sentence - what people love about PHP is that you can do whatever you like, armed with nothing more than a few HTML tags, whether or not you have a clue what the implications are, whether or not you can spell "security hole", whether or not there is any prospect of your code being maintained, even by the original coder, a week after it has been written. The stated aim of version 1 of Personal Home Page was to circumvent the unix user-based security system - the whole language is actually an exploit!

      It's the rails of Ruby on Rails that puts off PHP programmers addicted to "I started typing HTML and accidentally created a banking website, but someone hacked it before I could show it to you" (and Ruby is a lovely name for dumbed-down perl without a few gigabytes of CPAN modules).

      --
      Virtually serving coffee
    2. Re:Alright, enough with the dead language by Watson+Ladd · · Score: 1

      Real coders use Scheme or XCPE for web apps. Both obscure languages, both 30+ year old languages. And both amazingly powerful.

      --
      Inventions have long since reached their limit, and I see no hope for further development.-- Frontinus, 1st cent. AD
    3. Re:Alright, enough with the dead language by melonman · · Score: 1

      Real coders use Scheme or XCPE for web apps

      Real coders? So there is more than one person doing this?

      And both amazingly powerful.

      I don't doubt that Scheme at least is a wonderful language (although personally I prefer zetalisp). But how many libraries are there for, say, manipulating PDF, driving graphics packages or doing cryptography? Any coder who is reinventing every single wheel from scratch isn't a real coder. And how well does Scheme scale for web apps? How much native support does it have from, say, Apache? Can you preload? Can you compile at all for that matter, and, if so, do you have to do that offline and then fiddle around with binaries on the live server? Can you cluster? Can you serve a non-trivial page fast enough to cope with a busy website? Or are these real coders producing web apps for themselves and three dorm-room friends?

      --
      Virtually serving coffee
    4. Re:Alright, enough with the dead language by Anonymous Coward · · Score: 0

      I though PHP was 'PHP:Hypertext-Preprocessor'.

  20. WebCT Vista vs Yahoo Mail by apathy+maybe · · Score: 3, Interesting

    I 'use' (am abused by) WebCT Vista for my university studies. And it is crap.

    When using a web browser you would expect that the standard functions to work, back and forward buttons, multiple tabs on a site and so on. But WebCT Vista doesn't let you do that! Oh no, it restricts you to one page and the navigation is terrible.

    People already know how to use webpages, they do not need a new concept thrust at them, especially not a new concept that breaks the old.

    I think that Yahoo mail works really well, it is an example of an online app that works with in the web browser concept and offers interaction beyond that for those who want to learn.

    --
    I wank in the shower.
  21. Hammering a nail with an Exacto knife by Octopus · · Score: 2

    Look, the browser is still a two-dimensional (I guess two and a half, if you count pop-ups) document navigation application. If Ajax and other schemes, by their very nature, break out of this linear document structure without the cooperation of the browser itself, then that's what you get.

    I'm not dissing Ajax - I'm just saying it's best used in certain circumstances. The times when you don't WANT the user to have arbitrary control over navigation - such as a shopping cart checkout or CMS tools, in which they must be locked into a certain workflow for the sake of application structure, security, user hand-holding, or speed. Ajax is great for db-driven tools, especially when trying to get the speed and interactivity of a client application, plus greater control over navigation to avoid repeat POSTs, etc.

    I can appreciate that everyone is trying to innovate a way around this problem, and it seems there are some possible solutions with compromises - that's what makes new waves of tech like Ajax come into existence in the first place. But sometimes you just have to remember there's a time and a place for a certain tool.

  22. Logic Structure for History by cogito1002 · · Score: 1

    Ok, lets think about this one a little bit. I have no patience for toolkits and perfer to write my own code, and Im sure that there are other folks who want to figgure this one out and not just whimp out and borrow code from google.

    On Entering the page:
    1) check the url for a hash that would say which subsection if it exists load that section (this resolves the problem of bookmarks, as the string after the hash will identify the specific section)
    2) if there is no hash in the url, check for a cookie that is keeping track of the users location once again, if its there load that section (twice cook it, keep a cookie updated with the current section of the page, this also solves the problem of people using the back and forward buttons when entering and leaving the page, however does nothing for in page back and forward functionality)
    3) If there is no hash or bookmark you can assume this is a new user create a bookmark and load the default section.

    On clicking a link:
    Update the cookie, Update the hash, load the new section.

    This was just a quck thought, as Im a designer not a dev and dont have to do the dirty work myself most of the time. So Im just throwing this out to be picked apart.

  23. Those examples map to back/forward fairly well by patio11 · · Score: 1

    Back in a shopping cart should always be a contextual "cancel" -- if you're on the page asking for final authorization, its the same as "no". If you're on the page showing you the items you have ordered, its the same as "go back to shopping". Forward should always be the same as hitting the submit button -- forward on the "whats your address" form should process the form if it is sufficiently filled in or throw an error if it isn't. Forward on final authorization should get you "Thank you for this order!". For a CMS application the metaphors are different but the functionality should be pretty similar -- back when reviewing a draft causes the draft to be edited but not published, forward causes it to proceed to the next stage of the workflow.