Open A New Page For An External Link In The Nav Bar
Permalink 2 users found helpful
I'm not seeing a way to have the external link in a navigation bar open into to a new window? There is no option for target="_blank". Others have asked in the forums, but I haven't seen a clear answer. This is just for one of my links in the navigation bar, which leaves the site.
That is beautiful jjdb210. I would have never thought of that. You get a "red heart" for that one.
This is my solution using a autonav template and a Page Attribute called new_window.
Attached is new_window.php.txt - rename/move this to blocks/autonav/templates/new_window.php - I've commented out the original code so you can see the changes.
Create a new Page Attribute:
Open in a New Window new_window checkbox
Now when you add a new page, you will have a checkbox to Open in a New Window.
In Edit Page mode, click the autonav block, click Custom Template and select New Window.
This can also be done with header_menu, breadcrumb, etc.
Hope that made sense.
Attached is new_window.php.txt - rename/move this to blocks/autonav/templates/new_window.php - I've commented out the original code so you can see the changes.
Create a new Page Attribute:
Open in a New Window new_window checkbox
Now when you add a new page, you will have a checkbox to Open in a New Window.
In Edit Page mode, click the autonav block, click Custom Template and select New Window.
This can also be done with header_menu, breadcrumb, etc.
Hope that made sense.
in 5.4.1 there is a new attribute that will allow this
Figures, but hey it was worth learning how to do :)
Hey all. Here is a thinner way to do it using jQuery (and doesn't require updating your domain):
In case you are unaware, jQuery is automatically bundled with C5. So throw that in <script> tags into your header and you're set!
$(document).ready(function() { $("a[@href^=http]").each( function(){ if(this.href.indexOf(location.hostname) == -1) { $(this).attr('target', '_blank'); } } ) });
In case you are unaware, jQuery is automatically bundled with C5. So throw that in <script> tags into your header and you're set!
Hi DaveS,
That would make all external links open in a new window/tab - not *a* link in the autonav, like the forum question was asking for.
Nice clean jQuery code though.
That would make all external links open in a new window/tab - not *a* link in the autonav, like the forum question was asking for.
Nice clean jQuery code though.
True enough. Ran into some problems with that code anyway - so I went back to the one above. That's what I get for trying to help! LOL
@Mnkras Sorry for my ignorance, but can you please provide a link to how to do this? I have the latest version and don't see the attribute. Thanks.
Edit: Oh I see, it's in the dialog when you add the external link in the sitemap.
Edit: Oh I see, it's in the dialog when you add the external link in the sitemap.
Ugh... I don't see a way to add custom attributes to external links though, so I'm back to square one on this because my navigation relies on custom attributes for its images... Any help here is appreciated. I did have it go to a dummy page and used an htaccess redirect so I may have to try that route again and figure out a way to get the htaccess redirect to open in a new window??
I might be able to help if you remind me with html code or further explanation of what you mean by "attribute".
Thanks! Just noticed your reply now because I didn't realize I wasn't able to receive email notifications for a while.
To get the picture links in my navigation, I set Picture-on and Picture-off custom image attributes (under page properties).
The explanation of how it works is here:
http://www.codeblog.ch/2009/12/image-navigation-items/...
Now that I think about it, I suppose I could probably figure out how to set an attribute "open in new window" as well included in that code somewhere that might somehow do the trick... if you have ideas on the easiest way I'm all ears!
To get the picture links in my navigation, I set Picture-on and Picture-off custom image attributes (under page properties).
The explanation of how it works is here:
http://www.codeblog.ch/2009/12/image-navigation-items/...
Now that I think about it, I suppose I could probably figure out how to set an attribute "open in new window" as well included in that code somewhere that might somehow do the trick... if you have ideas on the easiest way I'm all ears!
Even better, I could probably set up a text attribute with the actual address of the external link...
Found a solution:
Create a new text attribute "external_link"
And use the following code:
Then, add the full URL to the external link in the external_link attribute for that page, and it should go to that page instead of the dummy one, without a redirect required. It still requires a dummy page, but at least you don't have to mess with redirects and it opens in a new window.
Create a new text attribute "external_link"
And use the following code:
$picOn = $_c->getAttribute('pic_on'); $picOff = $_c->getAttribute('pic_off'); //$picHover = $_c->getAttribute('nav_img_hover'); $external_link = $_c->getAttribute('external_link'); if ($picOn) { $linkTextActive = '<img src="' . $picOn->getURL() . '" alt="' . $linkTextActive . '"/>'; } if ($picOff) { $linkTextInactive = '<img onmouseout=src="'.$picOff->getURL().'" onmouseover=src="'.$picOn->getURL().'" src="' . $picOff->getURL() . '" alt="' . $linkTextInactive . '"/>'; } if ($c->getCollectionID() == $_c->getCollectionID()) { echo(' <li class="nav-selected nav-path-selected"><a class="nav-selected nav-path-selected" href="' . $pageLink . '">' . $linkTextActive . '</a>'); } elseif ( in_array($_c->getCollectionID(),$selectedPathCIDs) ) { echo('
Viewing 15 lines of 26 lines. View entire code block.
Then, add the full URL to the external link in the external_link attribute for that page, and it should go to that page instead of the dummy one, without a redirect required. It still requires a dummy page, but at least you don't have to mess with redirects and it opens in a new window.
It allows you to check the box, but I still haven't gotten it to function properly. It never opens up in a new window.
To my knowledge there is no way currently to do this via the C5 admin panel...
You can modify a the autonav template to add this support (I haven't personally gone that route yet)...
The route I tend to use (simply because it tends to be the quickest for me, and I apply it to all links, not just the ones in my navigation), is to use Javascript to apply the new window to any "outbound" links... This simple javascript added to the head does a pretty good job of it:
(Don't include the <?php ?>, the forum seems to be adding that on my behalf...)... Also, be sure to replace the domain name with your domain name...