JQuery Address - Reverse Buttons

Hi, I am trying to get the AJAX website and jquery.address-1.3.2.min.js to work.

I have .click () events using .load to update a DIV that works successfully. I updated, for example: rel = "address: profile", and I see the URL, changing it when I click on different links.

I also added this code:

$(function() { $.address.change(function(event) { alert('here'); }); }); 

I see that the .change () event is being fired.

I'm not sure how to write the code to actually get the back / forward buttons (sorry I'm new to JQUERY). I saw examples on the Internet, but still confused. Hope this is a really simple example.

I also need to re-run .load () to load the DIV again. At the same time, the warning trigger is not isolated for backlinks or transitions to browser buttons.

Thankyou

+4
source share
3 answers

Now you need to make the necessary changes to your div inside the $.address.change() event in order to switch to the desired state, all page state changes will go inside this event.

In the jquery address, you need to perform two main tasks: first, so that your links change the value of the deep binding, using events like you, but forcing them to update the $.address.value(value_here) method; and secondly, catch all the changes using the change() event to apply changes to the state of your page.

You can also use the value() attribute to determine the correct state, e.g.

 $("a").onClick(function () { //You dont need this part if you used $address.value($(this).attr('href')); //the 'rel' attribute in the links }); $.address.change(function(event) { //Catching URL change in `event` $.ajax({ //You said you're using AJAX so url: "."+event.value+".html", //using `value` attr. to get the URL+html cache: true, success: function(response) { $("#content_div").html(response); //loading page in div using AJAX } }); }); 

this is just an example, you can use it to load your pages in any other way, since $.address.value() returns the value after # , this is your deep binding value.

Once you do this, the Back and Forward buttons will change the URL of the page, the change() event will catch this, and your page will work as expected.

So basically you need to develop a certain level of understanding of how the jquery address works and work with this code. Also on the dquery address docs docs page is a list of all methods and events if you forget about them.

+2
source

I don’t really understand your question, but if you are trying to get the button to work with the ajax page (for example, you change the hash and return to the previous button with feedback), I suggest using Ben Alman jQuery BBQ .

There are some good lessons and this is great for me.

0
source

When choosing a plugin to subscribe to hash changes, keep in mind that the new version of jQuery does not support browser detection, they work with function detection. Because of this, some old plugins no longer work. This happened to me when I wanted to use the jQuery address. The plugin that worked for me is called Path.js ( https://github.com/mtrpcic/pathjs ). My context: a page with several steps, and I wanted me to be able to return to the previous state using the browser's back button. Here's how I set it up:

  Path.map("#2").to(function () { showStep2Page(); // hides the current DIV and shows the step 2 DIV }); Path.map("#1").to(function () { showStep1Page(); }); Path.map("").to(function () { // this allows me to go to the first step and show the step 1 DIV showStep1Page(); }); Path.listen(); // listens to changes in URL hash (after the pound sign (#)) 
0
source

Source: https://habr.com/ru/post/1340911/


All Articles