I'm doing partial update to the page with Ajax which is a shopping cart that updates with Ajax as users add items to it. The problem is that if users move to checkout and then hit the back button the shopping cart looks empty as it was updated with Ajax. Refreshing the page make items appear again.
Is there a way to force updating the page on back button?
If you use the history.pushstate in your ajax app, you can keep the contents of the card in a variable in the global namespace (e.g. window.cartItems = { item1, item2, ... }), and after back button is pressed and the previous button is rendered again, get your items from that global object.
I would recommend against altering the behavior of the back button itself. Users expect the Back button to take them back a page, not to do anything else.
I would suggest a different approach. For example, you could have a piece of JS that runs on the cart page itself. This script would grab all the cart data from the backend. The script could run once when the page loads, ensuring that the cart is up-to-date.
Related
From my Side Menu, I have a view that loads two calls for action - scan barcode or search product when initially loaded. Once I a make a selection, the rest of the view is dynamically populated. Once it is dynamically populated and if I go back to the Side Menu to reload the view so that I can only see my original calls for action, I cannot see that. Instead I still see the dynamically populated state. At the beginning of the controller I have the following calls. $ionicNavBarDelegate.showBackButton(false), $ionicHistory.clearHistory(), $ionicHistory.clearCache().
I tried initializing the view with an empty function so that it causes the scope to reset however that didn't not help. Is there a way to trigger a fresh session every time I launch from the side menu?
I was able to resolve this by creating an empty controller that will redirect me to myview. The refresh worked magically every time.
I am using joola2.5 and virtuemart 2.6.6. I have the modal pop up box enabled which pops up when I perform an add to cart operation (where I have embedded add to cart buttons in the category view).
The problem is that after adding the item the next page that is loaded is the last category that I browsed to. I would like to be able to return to the exact same page before clicking add to cart. Not sure if this is a bug, but would there be a simple variable that is stored and called to remember the last page? I guess I can just add this in the code near the add to cart button but I have no idea what it would look like or how it would be implemented.
Try clearing your cache after activating SEF. Make sure you remove all cookies. It works on my machine, but slider is missing off front page. Good luck.
I have seen history.js, it seems just work on current page:
such as:
www.mysite.com
www.mysite.com/?state=1
www.mysite.com/?state=2
www.mysite.com/?state=3
www.mysite.com/?state=4
www.mysite.com/?state=3
It can make back button back follow state from large to small only on the same page.
What I want is:
www.mysite.com/center/?state=1
www.mysite.com/product-list/?state=2
www.mysite.com/product-detail-manage-form/?state=3
center can not return to product-list, and product-list can not return to product-detail-manage-form.
Because a user can edit or delete a product at product-detail-manage-form page, and server will redirect he to product-list page after form submit.
I don't want he return to product-detail-manage-form by clicking back button on product-list page.
Is there any easy way to achieve my purpose?
Try using javascript to manipulate the browser history: https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history
This way you can control the history stack and which pages the users can get to using the back button
I'm making a webshop for a school project, and i've got an issue with the shopping cart. because the shoppingcart & webshop are in different iframes on the main page(got quite a few images on main page, don't want to reload that, thats why it's in iframes).
Basically, my issue is that when something is selected in the webshop, the shopping cart doesn't update untill the entire webpage is reloaded. I'm storing shopping cart info in an array in a SESSION variable. basically, what i want is to reload the iframe of the cart when the session variable changes.
If the answer involves anything besides PHP/javascript, please give a clear explaination/example code, i've never used anything outside of PHP/js/html/css before. Thanks in advance :) been stuck on this for a few days now :S
Create a javascript function to fire the following code when a user adds something to their cart:
document.getElementById('some_frame_id').contentWindow.location.reload();
I don't have the code in front of me, but I've done something similar where in the parent you create an event listener on "message" then in the iframe you can call parent.postMessage, works as long as they are on the same domain
Although APAD1's answer directly addresses what you asked, it sounds like your program has some deeper design problems. Using iframes for content from the same site (ie within one domain rather than content from a separate site) is bad practice.
Consider instead displaying content in <div>s with unique ids, and using javascript to update the contents of those divs. If you're using PHP on the back end, you can create a "page" that only generates the cart contents part of your page. Not only can you include it in each page without changes, but you can load it directly with javascript and insert the result into the current page to update it in place.
Whenever your user adds an item to their cart, you can call the javascript method that refreshes the <div> with the cart's contents.
I am having problem while using onclick="javascript:history.back();" with Aspnet. In the first page i filled some data and click search button it show some results, i click on particular result for its details which navigate to the 2nd page but when i click on custom back button it refresh the page and all data set to initial values,when i use onclick="javascript:history.back();" I get nothing but the page displays "webpage has expired."
Thanks in advance!
This is because you are using HTTP POST for your search page.
If you use HTTP GET (putting your parameters in the querystring) - then the browser won't display this message.
This has nothing specifically to do with ASP.NET. It's a (sensible) browser behaviour to prevent you from repeating an action that may have undesirable impacts (for instance, sending two copies of an order)