jquery-address
jquery-address copied to clipboard
$.address.change() is loading twice whenever refresh page
hi,
whenever i refresh a page, that time $.address.change is loading twice.
$.address.change(function(event){ alert(event.path); });
please help me, how to solve this problem, and also give me a example of internalChange and externalChange event handler
the same problem here but it only occurs in chrome and safari, works perfect in firefox and opera
I would double check that the reference to the address plugin is not included twice on the page.
I only suggest because we experienced a similar issue where $.address.change fired twice. It turned out the script file had been included on the master page, but also included on a sub-page by accident.
You can always check the url where the plugin was initialized to event.path and skip the load if they are the same. Works well and does not affect other browsers. You should only use it as a last resort tough, something else must be causing double load.
ie browser is first loading home page and after redirect to original page. what was i mistaken in my codes.
.htaccess files
in footer file having the following code
var init = true, state = window.history.pushState !== undefined;
$.address.state('').init(function(){
$('a.rwajax').address(function(){return getUri($(this).attr('href'));});
}).bind('change', function(event) {
var qstring = '';
if(event.value != event.path){
qstring = '?' + event.queryString;
}
var url = $.address.state() + event.path + qstring;
if (state && init) {
init = false;
}
else{
load_page(url+' #inside','div#content_container');
return false;
}
});
please help me, how to initialize the htaccess and $.address().
var init = false;
state = window.history.pushState !== undefined;
$address.init(function(){
//stuff
}).change(function(){
if (state && init)
init = false;
else{
//run code
}
The jquery address plugin is not designed to work inside the document ready function. Verify your code. See #119.
Also, if you are setting the state
option, all URLs but the root will be redirected if you are using a non-HTML5 browser (like IE < 10), causing the change()
event to be called twice. I.e., for state('\')
, the URL http://host.com/page/
will be redirected to http://host.com/#/page/
. See #95.