External Links not opening in new window

Permalink
I created a superfish menu for a site I've just put live: betapond.com and there is an external link to a product site of theirs in the dropdown. I have this set to open in a new window but it's opening in the same one. Is there something in the way I have the menu coded that is preventing this?

PassionForCreative
 
MattWaters replied on at Permalink Reply
MattWaters
I added a regular SF block and an external link to on my test site and SF seems to respect the "Open link in new window" attribute on external links. I tested it in both the top level and sub-menu items.

Looking at view.php between line 106 and 120, you can see where it adds target="_blank" to link tags as needed.

Are you hard-coding this block? I wonder if that could have something to do with it...
PassionForCreative replied on at Permalink Reply
PassionForCreative
Hi Matt, I've coded the menu in by hand rather than use the Superfish block from the marketplace.

Script:
<script> 
    $(document).ready(function() { 
        $('ul.sf-menu').superfish({ 
            delay:       1000,                            // one second delay on mouseout 
            animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
            speed:       'fast',                          // faster animation speed 
            autoArrows:  false,                           // disable generation of arrow mark-up 
            dropShadows: false                            // disable drop shadows 
        }); 
    }); 
</script>


HTML:
<?php  
   defined('C5_EXECUTE') or die(_("Access Denied."));
   $aBlocks = $controller->generateNav();
   $c = Page::getCurrentPage();
   $containsPages = false;
   $nh = Loader::helper('navigation');
   //this will create an array of parent cIDs 
   $inspectC=$c;
   $selectedPathCIDs=array( $inspectC->getCollectionID() );
   $parentCIDnotZero=true;   
   while($parentCIDnotZero){
      $cParentID=$inspectC->cParentID;
      if(!intval($cParentID)){
         $parentCIDnotZero=false;
      }else{


CSS:

.sf-menu { position: static !important;
}
.sf-menu ul { margin: 0 !important; padding: 0 !important; float: right; }
.sf-menu ul ul { position: static; width: auto; }
.sf-menu ul li { 
   float: left; 
   position: relative; 
   border: 1px solid transparent;
   margin: 0 0 0 15px;
   behavior: url(http://www.betapond.com/packages/theme_betapond/themes/betapond/javascripts/PIE.htc);
}
.sf-menu ul li.lastItem { background: none; }
.sf-menu ul li a { 
   display: block; 
   color: #ffffff;
MattWaters replied on at Permalink Best Answer Reply 1 Attachment
MattWaters
Here's some code that should work-- it checks for the openCollectionPointerExternalLinkInNewWindow method, sets the value of variable based on that, and prints the required target="_blank" attribute in SF's link html if the page is set to open in a new window.

All I did here was take a look at how our packaged Superfish add-on is set up, and then added the missing parts to your code.

// check to see if open link in new window is set
         if(method_exists($_c,'openCollectionPointerExternalLinkInNewWindow') && $_c->openCollectionPointerExternalLinkInNewWindow()) { 
         $newWindow = 1; 
      } else { 
         $newWindow = 0;
      }
         if ($c->getCollectionID() == $_c->getCollectionID()) { 
            echo('<li class="nav-selected nav-path-selected"><a class="nav-selected nav-path-selected" href="' . $pageLink . '" '.($newWindow?'target="_blank"':'').'>' . $ni->getName() . '</a>');
         } elseif ( in_array($_c->getCollectionID(),$selectedPathCIDs) && $_c->getCollectionID() != 1) {
            echo('<li class="nav-path-selected"><a class="nav-path-selected" href="' . $pageLink . '" '.($newWindow?'target="_blank"':'').'>' . $ni->getName() . '</a>');
         } else {
            echo('<li><a href="' . $pageLink . '" '.($newWindow?'target="_blank"':'').'>' . $ni->getName() . '</a>');
         }


I included the full code as an attachment. Let me know how this works for you.
PassionForCreative replied on at Permalink Reply
PassionForCreative
That worked perfectly. Thanks for taking the time to modify my view file.
JoshRendezvous replied on at Permalink Reply
JoshRendezvous
That's awesome! This is the best response to this old superfish problem there is out there! Nice going Matt!! Fixed it perfectly.