I try to change the URL link (href
attribute) when I click on a URL after following link and loading page. I tried this:
<a href="http://example.com/ASC/" class="sort_loading_country">link</a>
jQuery( ".sort_loading_country" ).click(function() {
str = jQuery(".sort_loading_country").attr("href") ;
if ((str.indexOf('ASC') + 1) > 0) {
new_str = str.replace(/ASC/g, "DESC");
jQuery(".sort_loading_country").attr("href", new_str);
}
});
This changes the URL, but after clicking on the link open new page with new url. I want change the URL after opening page and following the link. I tried this too:
jQuery(".sort_loading_country").click(function() {
str = jQuery(".sort_loading_country").attr("href");
jQuery(document).ready(function() {
if ((str.indexOf('ASC') + 1) > 0) {
new_str = str.replace(/ASC/g, "DESC");
jQuery(".sort_loading_country").attr("href", new_str);
}
});
The same behavior, click on the link - then open new page with new url. I want that when I click on the link open page with old url and after that change url to new in href. Am I missing anything ? Anybody knows how to change attribute href after loading page with old URL ?
Aucun commentaire:
Enregistrer un commentaire