Given: slider (photoswipe).

When changing the picture, we change the url without reloading the page. Further more. There is a desire to put a banner next to the picture. The banner is located in the iframe with an idish. There is no problem updating the banner.

$('#id').attr('src', $('#id').attr('src')); 

I want to bind the above function to change urla. Everything works if I hang this event on any click. But we need to keep track of address changes. I would be very happy to help.

Shoveled half of the Internet. Something about

 window.onhashchange 
  • one
    What function change url? In it and put a banner change. - Visman
  • So why window.onhashchange didn't please? - Sergey Snegirev

2 answers 2

Try a fairly simple jQuery plugin http://benalman.com/projects/jquery-hashchange-plugin/

 $(window).hashchange(function () { var hash = location.hash; var res = (hash.replace(/^#!\//, '') || 'blank'); console.log('hashchange', res); }); 
  • Thank. But I wanted no third-party plug-ins. - Ivanrrr pm

pre-form uri, then transfer to the method:

 var stateParameters = { foo: "bar" }; history.pushState(stateParameters, "New page title", "/category/tech/page/2"); 

You can intercept the url change event using the method:

 $(window).on('popstate', function(e) { // current href: document.location.pathname Application.updateState(); }); 
  • Interesting. And you can read more? Suppose I have a website: site.ru Then I go to an old woman: site.ru/pages/555 On the page I click on the picture and get: site.ru/pages/555#&gid=1&pid=1. Another picture has the address: site.ru/pages/555#&gid=1&pid=2. and so on. How can I pull an iframe with an advertisement when changing a picture? - Ivanrrr 1:51 pm