Links on homepage and nav bar to open in a new tab

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
wilmira
Veteran Member
Posts: 67
Joined: 2013-07-11 18:00

Links on homepage and nav bar to open in a new tab

Post by wilmira » 2014-10-08 21:01

Hello,

I have created 2 links on my homepage and in the menu nav of my application, however I would like those 2 links to open in a new tab, Is that possible?

Thanks in advance,

Wilfredo

udayvatturi
AppGini Super Hero
AppGini Super Hero
Posts: 85
Joined: 2014-06-14 03:08
Location: India
Contact:

Re: Links on homepage and nav bar to open in a new tab

Post by udayvatturi » 2014-10-09 09:54

Hi
use target="_blank" to open in new tab.

Example:

Code: Select all

<a target="_blank" href="http://your_url_here.html">Link</a>

wilmira
Veteran Member
Posts: 67
Joined: 2013-07-11 18:00

Re: Links on homepage and nav bar to open in a new tab

Post by wilmira » 2014-10-16 16:00

Thank you for your response Uday,

However the link is in an array:

$navLinks[] = array(
'url' => 'http://my_url.php',
'target' => '_blank',
'title' => 'Print invoices',
'groups' => array('*') // groups allowed to see this link, use '*' if you want to show the link to all groups
);
$navLinks[] = array(
'url' => 'http://my_url.php',
'target' => '_blank',
'title' => 'Go to my webpage',
'groups' => array('*') // groups allowed to see this link, use '*' if you want to show the link to all groups
);

This is in the links-navemenu.php hook.

As you can see, I have added the target in the array, but it is not working.

Wilfredo

peebee
AppGini Super Hero
AppGini Super Hero
Posts: 352
Joined: 2013-03-21 04:37

Re: Links on homepage and nav bar to open in a new tab

Post by peebee » 2014-11-05 04:00

Hi Wilfredo,

I had the need for the same nav-links behaviour and managed to achieve it by adding the 'target' array to links-navmenu.php and editing the generated lib.php. The following edits don't affect any existing generated navmenu links and you can specifiy whatever 'target' attribute you want for any additional links:

to open a link in a new tab, in links-navmenu.php add the 'target' array, as follows:

Code: Select all

$navLinks[] = array(
	'url' => 'path/to/link', 
        'target' => '_blank',
	'title' => 'Link title', 
	'groups' => array('group1', 'group2'),
	'icon' => 'path/to/icon'
);
then edit lib.php as follows:

find and replace (somewhere around line 102)

Code: Select all

// custom nav links, as defined in "hooks/links-navmenu.php" 
	global $navLinks;
	if(is_array($navLinks)){
		$memberInfo = getMemberInfo();
		$links_added = 0;
		foreach($navLinks as $link){
			if(!isset($link['url']) || !isset($link['title'])) continue;
			if($memberInfo['admin'] || @in_array($memberInfo['group'], $link['groups']) || @in_array('*', $link['groups'])){
				if(!$links_added) $menu .= '<li class="divider"></li>';
				$menu .= "<li><a href=\"{$link['url']}\"><img src=\"" . ($link['icon'] ? $link['icon'] : 'blank.gif') . "\" height=\"32\"> {$link['title']}</a></li>";
				$links_added++;
			}
		}
	}
with this:

Code: Select all

// custom nav links, as defined in "hooks/links-navmenu.php" 
	global $navLinks;
	if(is_array($navLinks)){
		$memberInfo = getMemberInfo();
		$links_added = 0;
		foreach($navLinks as $link){
			if(!isset($link['url']) || !isset($link['title']) || !isset($link['target'])) continue;
			if($memberInfo['admin'] || @in_array($memberInfo['group'], $link['groups']) || @in_array('*', $link['groups'])){
				if(!$links_added) $menu .= '<li class="divider"></li>';
				$menu .= "<li><a href=\"{$link['url']}\" target=\"{$link['target']}\"><img src=\"" . ($link['icon'] ? $link['icon'] : 'blank.gif') . "\" height=\"32\"> {$link['title']}</a></li>";
				$links_added++;
			}
		}
	}
Available 'target' attributes:
_blank Opens the linked document in a new window or tab
_self Opens the linked document in the same frame as it was clicked (this is default)
_parent Opens the linked document in the parent frame
_top Opens the linked document in the full body of the window

I hope that helps.

wilmira
Veteran Member
Posts: 67
Joined: 2013-07-11 18:00

Re: Links on homepage and nav bar to open in a new tab

Post by wilmira » 2015-06-23 04:08

I have found a very simple way to achieve this. Jus add this to the URL: " target="blank" in the links-navmenu.php. The code then is like this:

$navLinks[] = array(
'url' => 'path/to/link" target="_blank"',
'title' => 'Link title',
'groups' => array('group1', 'group2'),
'icon' => 'path/to/icon'
);

Wilfredo

Post Reply