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?
Hi Matt, I've coded the menu in by hand rather than use the Superfish block from the marketplace.
Script:
HTML:
CSS:
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{
Viewing 15 lines of 69 lines. View entire code block.
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;
Viewing 15 lines of 98 lines. View entire code block.
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.
I included the full code as an attachment. Let me know how this works for you.
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.
That worked perfectly. Thanks for taking the time to modify my view file.
That's awesome! This is the best response to this old superfish problem there is out there! Nice going Matt!! Fixed it perfectly.
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...