
|
View Full Version : ajax > back, refresh buttons
mikey1090 09-26-2006, 09:50 AM Hi, i have been learning ajax for a while now.
The time has come where i need to learn how to fix the back button etc.
I am using ajax to load content into a div.
Yes, using ajax is right for my site, so no need to tell me not to use it.
It will save me bandwidth, and also saves me reloading all images, security queries etc.
Anyway....to the point. users log in to get to this part of the site, so they will never bookmark it.
But with them doing things like sending mails, spending resources etc they will use the browser buttons that ajax has broken.
So i need a simple way to fix it. There are loads of tutorials out there, but i have tried a few.....they are either too complicated or just dont work
i need someone to spell it out for me, tell me the most simple way to do it.
I use php in my site, and quite a lot of javascript of course, so im not stupid with either of them :stickout:
Please help
mike
nnormal 09-26-2006, 01:01 PM I would very much like to hear this too...
mikey1090 09-26-2006, 01:49 PM i have heard you can use cookies, iframes, #int the browser
but i can't make any sense of it all
StickiWidgets 09-26-2006, 02:04 PM I'm not sure what you mean by ajax breaks the browser buttons. I've used ajax on some projects and it does not "break" the browser. ;) But, if you mean that by using the broswer buttons you lose the state of the page then you can use cookies to save the state so when users come back they are where they left off.
If you can explain the specific problem then I'm sure I or others will be able to give you a simple fix.
nnormal 09-26-2006, 02:39 PM the problem is when you have some sort of content frame and your nav is just pulling content into those frames via ajax, you never leave the page in terms of your browser history. so when someone hits the back button they go clear out of your site or whereever they were before that. what you want to have happen is the history to remember the requests and act as if they were browsing with standard hrefs. there is some trick to this with using frames and writing to history objects but I havent really ever gotten it.
discobean 09-26-2006, 06:50 PM "The time has come where i need to learn how to fix the back button etc."
"i need someone to spell it out for me, tell me the most simple way to do it."
How about, don't use ajax to imitate a browser?
That Guy 09-27-2006, 03:22 AM I don't know what you're talking about kinda, but if you want to fix back/refresh stuff and assuming you're using an iFrame, you could create the iFrame dynamically with Javascript.
nnormal 09-27-2006, 10:18 AM "The time has come where i need to learn how to fix the back button etc."
"i need someone to spell it out for me, tell me the most simple way to do it."
How about, don't use ajax to imitate a browser?
you missed one
Yes, using ajax is right for my site, so no need to tell me not to use it.
foobic 09-27-2006, 10:32 AM Top Google result:
http://www.contentwithstyle.co.uk/Articles/38/
In simple terms, use links that are anchors on the current page. Then each click adds an item to the browser history without reloading the page and the back button also keeps you on the same page.
nnormal 09-27-2006, 10:52 AM (links) are modified to change the src attribute of the iframe, loading a page called mock-page.php with a querystring that contains the same argument as the hash did before. A timer polls the iframe for it's location and if it detects a change then a content load is triggered in the AJAX app. This is complicated by the fact that the iframe's src property doesn't change when the back button is pressed. To get around this I've written a little function to sit within mock-page.php and report it's location when asked.
When a change in mock-page.php's url is detected an AJAX content load is triggered and the parameters from it's querystring are duplicated into the url, to make sure that bookmarking will still work. It's sounds a bit convoluted but the code is quite straight forward. Except for one thing... IE wouldn't let me access the window.location immediately. I have no idea why... As a simple workaround, I've added a tiny 100ms delay to the firing of the script, which seems to sort it out.
this makes my head hurt :s
nnormal 09-27-2006, 10:54 AM use links that are anchors
this doesnt work in IE and while i hate IE most of the web still uses it
foobic 09-27-2006, 11:25 AM this doesnt work in IE
I saw he said that but in regular pages anchor links do go into the history in IE (find any page with lots of anchors and try it). It must be some other aspect of the ajax interaction that fails in IE.
If that could be fixed you could avoid all that iframe mess altogether... Hmm, another project for someday!
mikey1090 09-27-2006, 12:47 PM have any of you managed to successfully get this to work? i have been trying for a long while, and i have read that "contentwithstyle" webpage, i even downloaded the source....but i could get it to fit in with my site.
people mention generating an iframe or using cookies....but i dont know why...or how....and how i can get this to fit in with my site.
grabmail 10-07-2006, 09:49 AM just use dojo. they have built-in support for back buttons
mikey1090 10-07-2006, 05:21 PM are there any other ajax libraries that support the back button? one that is simple and that i can easily build around my site?
Burhan 10-08-2006, 03:24 AM Wow ...
It will save me bandwidth
No, this is not what AJAX does, no matter what you have been told or think is apparent.
users log in to get to this part of the site, so they will never bookmark it.
This is a very dumb assumption. Don't build your site around the idea that you can predict what users will and won't bookmark.
are there any other ajax libraries that support the back button? one that is simple and that i can easily build around my site?
Normally, you build your site around a framework, not you build a framework around your site.
Either way, the best established practice is to NOT fiddle with the back button or change its accepted behavior. Namely, because depending on user's browser or security settings your neat tricks might not work and lead to further frustrations.
I suggest you rethink how you are designing this.
|