Search code examples
htmlrel

Adding "nofollow" to existing rel attribute


I´m trying to add nofollow to a link with an existing rel attribute that triggers an iframe popup.

Here is the link I am trying to alter:

<a class="modal" rel="{handler: 'iframe', size: {x: 700, y: 550}}" 
title="Email" href="/myurl.html">link text...</a>

The question is, how do I add nofollow to the rel attribute without messing up the popup?

I have tried this, but it comprimizes the popup release:

<a class="modal" rel="nofollow {handler: 'iframe', size: {x: 700, y: 550}}" 
title="Email" href="/myurl.html">link text...</a>

Solution

  • you can try having the links with rel="nofollow" so search engines can read it, and then you can change that value onclick. like this

    <a id="mylink" rel="nofollow" onclick="return changerel(this);" href="#">link</a>
    
    <script type="text/javascript">
    function changerel(el)
    {
        var myreplace = "{handler: 'iframe', size: {x: 700, y: 550}}";
    
        alert('rel before:'+el.rel)
    
        el.setAttribute("rel", myreplace);
    
        alert('rel after:'+el.rel);
    
        if (el.rel != myreplace)
        {
             el.onclick();   
        }
    }
    </script>
    

    see it in action here http://jsfiddle.net/5Basb/4/