I know there are many questions about jQuery + Back button issues, but it seems that they're trying to maintain history features when clicking the browser back/forward buttons.
My question is that when clicking the back/forward button, how can I load ajax-affected html page?
For example,
In index.html, dynamically remove all "div" elements from the list using AJAX (jQuery.post()).
Press the browser back(or forward) button to go to newpage.html.
Press the browser forward(or back) button to go to index.html again.
PROBLEM: the html page contains the deleted "div" elements.
How should I load index.html with no "div" elements after step (3)?
I'm currently using jQuery and Django as backend.
Thanks!
Use the jQuery history plugin to encode the application state. See their Demos page for examples of how to do what you want.
Related
I have a packaged web application with multiple ajax calls that will load html content in the middle of the website.
Is there a way to go directly to one of the ajax calls from the URL instead of manually clicking the buttons to reach the required content on the page immediately?
As a sample, i want to show the content of this page like i clicked the button without clicking it using JavaScript, jQuery, or manual click.
https://www.w3schools.com/xml/tryit.asp?filename=tryajax_first
I am trying to navigate to another HTML file without changing pages. Basically I got an emergency button, and once clicked, it should open an HTML file which pops up a box displaying 3 other buttons. This box also has an "X" to close the window, to close this HTML file and go back to the other.
Basically I want 2 html files to display at the same time. I am currently using adobe edge animate to do the process, however I am capable to use Javascript and HTML.
To give you an idea: It is similar to when visiting a website and a box pops up asking you if you want to subscribe to the news letter, or just keep searching.
Thanks
Well. what i understand of your question. You want an html page on an html page. I suggest you could use JQuery popup screen. Visit this link. https://jqueryui.com/dialog/
If you want to call another html page without refreshing your page use Jquery .load(). http://api.jquery.com/load/
$( "#div_to_load_file_in" ).load( "path/to/your/file.html" );
I am a first poster here so please excuse my noob-like behavior.
I have a button on my website that when pressed should disappear, and a form should be echoed out in its place without a page refresh.
I have easily achieved this with JavaScript / AJAX, but if JavaScript is disabled, I still want the button to do it's task.
My question is: Can I do this only using PHP, WITHOUT a page refresh?
Cannot comment or I would have but the answer would be no. PHP is server side so the only way for it to update a view is to reload to a new page. Also, I would think it is very unlikely to run into a situation where JS is disabled these days.
Not in a way I think you'd want to do it, but you could use an iframe that contains the button. The button would be a link or form submit and the navigation would happen inside the iframe to your form. This way, only the iframe is refreshed, but the full page remains unchanged.
You can only aciehcve this using ajax. You can force your users to enable
javascript noscript tags
<noscript>
<p>This page requires a JavaScript-enabled browser.</p>
</noscript>
I'm using jQuery Mobile (no php or xml or anything else) for a web application running on cherrypy and i would like to find out how can i keep the page as it has been set by user even after refreshing.
As an example of the page, see this fiddle: http://jsfiddle.net/xaKXM/5/
in this example, user may input certain text in Response number and description. When the user click submit,user will see #configtable div. if the page is refreshed, user will not go back to the initial page (#labels div' )but to remain in the#configtable` (the one that user can't input anything but can only click activate button")
May be there is a button that would clear all those states and the page will go back to default when refresh?
Is this possible to be done?
if you refresh the DOM using window.open('index.html'); this should clear everything in the page
I am trying a new functionality for my web site. I want to do simple navigation by hiding/showing <div> elements.
For example, when a user clicks a "details" button on some product, I want to hide the main <div> and show the <div> containing the details for the product.
The problem is that to go back to the previous "page", I have to undo all the display/visibility style changes, which is ok if the user clicks the "close" button in the newly opened <div>. But most users will hit the BACK button.
Is there a way to make the BACK button go back to the previous "state" of the page i.e., undo the visibility/display changes?
Thanks.
Yes. What you're looking for is called AJAX browser history.
There are a few open implementations out there, like RSH as well as plugins/modules for frameworks like jQuery and YUI.
to answer the question of your title (that's what I was looking for)
Using the BACK button to revert to the previous state of the page
and from the link from #reach4thelasers's answer, you have to set up a timer and check again and again the current anchor:
//On load page, init the timer which check if the there are anchor changes each 300 ms
$().ready(function(){
setInterval("checkAnchor()", 300);
});
because there's no Javascript callback triggered when the BACK button is pressed and only the anchor is changed ...
--
by the way, the pattern you're talking about is now known as Single Page Interface !
You need to add an anchor to the URL whenever a change is made
www.site.com/page.html#anchor1
This will allow the browser to maintain the pages in its history. I implemented it in my current site after following this tutorial, which works great and gives you a good understanding of what you need to do:
http://yensdesign.com/2008/11/creating-ajax-websites-based-on-anchor-navigation/
Your example in the comments won't work, because it works like this:
Page Loaded
Page Changed, Add Anchor to URL (back button takes you back to back to 1)
Page Changed, Anchor Changed (back button button takes you back to 2)
Page Changed, Anchor Changed (back button button takes you back to 3)
.... and so on and so on..
If there is, it sounds like a pretty evil thing to do from a UX perspective. Why don't you design a "back" button into your application, and use design to make it obvious to the user that they should use your application's back button instead of the browser.
By "use design," I mean make your application look like a self-sufficient user interface inside of the browser, so the user's eye stays within your page, and not up on the browser chrome, when they are looking for controls to interact with your app.
You can do this with anchors, which is how it's done in a lot of flash applications, or other apps that don't go from page to page. Facebook uses this technique pretty liberally. Each time the user clicks on a link that should go in their history, change the anchor on the page.
So say my home page link is:
http://www.mysite.com/#homepage
For the link that works your javascript magic, do this:
My Other Page
This will send the user to http://www.mysite.com/#otherpage where clicking the back button will go back to http://www.mysite.com/#homepage. Then you just have to read the anchors with
window.location.hash
to figure out which page you're supposed to be on.
Take a look to this tutorial based on ItsNat a Java web framework focused on Single Page Interface web sites