Hello, The page has links of the form:

<a class="ifr" id="popup" href="/article/234">Текст</a> <a class="ifr" id="popup" href="/article/235">Текст</a> ... 

How to make, that when clicking on links with given id to href, one more parameter was added at the end? For example: / article / 235 / popup But the look of the link itself for the user and search engines should not change ...

 $ (document) .ready (function () {
     $ ("a # popup"). each (function () {
         $ (this) .attr ("href", $ (this) .attr ('href') + '/ popup');
     });
 });

Such a script does not fit - it changes all the links initially ... and I only need to click. So that the user could not see and copy such links.

Ideally, make links of the form

 <a class="ifr" hrefattrs="/cmd=PopLayer" id="popup" href="/article/235">Текст</a> 

And when you click on the link to href if set to hrefattrs hrefattrs joined.

Tell me how to implement? Thank you in advance.

    1 answer 1

     $(document).ready(function(){ $("a.ifr").click(function(){ var newUrl = $(this).attr('href') + $(this).attr('hrefattrs'); console.log(newUrl); window.location.href = newUrl; return false; }); }); 

    Do not duplicate the id DOM elements.

    • 2
      the left attributes are better in data- , the author hardly knows about this, that's why he just wrote right away. - teran
    • teran, I vkurse about data-href = "" ... Just looked at my classmates hrefattrs = "" - Revenge-R
    • @Igor, strange but not working. Just follow the link from href without adding anything. - Revenge-R
    • In principle, $ (this) .attr ("href", $ (this) .attr ('href') + $ (this) .attr ('hrefattrs')) works; return false; But it adds naturally undefined when the hrefattrs is not specified And duplicates the hrefattrs when pressed again ... (for example, if the user opens _blank and then returns and clicks again) :( Who knows how to solve? - Revenge-R
    • @Igor Thank you for the desire to help ... There are a couple of questions: 1. And if hrefattrs is not set? - there will be an error undefined 2. Is there any kind of replacement for location.href in this case ... because after the click this link will open in my iframe via fancybox ... and for location.href it will simply drop to a redirect. - Revenge-R