Open menu link in new tab?

Started by Sir Osis of Liver, July 28, 2019, 11:16:42 PM

Previous topic - Next topic

Sir Osis of Liver

Tinkering with adding a new menu button in 2.1 ACP to this support forum.  There are a couple of ways to make it work in same tab, but am unable to open new tab.  I've used redirectexit() and window.location, both open in same tab.  Different permutations of window.open are blocked as unrequested popups.  There's a link in Support and Credits that also loads in same tab.  Any way to load a menu link in new tab?
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Antechinus

#1
Have you tried target="_blank"? That's the classic way of opening links in new tabs.

<a href="http:www.zomgwarezandpr0n.org" target="_blank" rel="noopener">Linky</a>

Arantor

It's also a security hole if you don't add rel="noopener" to the link.

Antechinus

Oh yes? Handy tip. I haven't seen that mentioned anywhere, but I'll make sure I incorporate it in future. Have edited the code above.

Arantor


Sir Osis of Liver

Quote from: Antechinus on July 29, 2019, 05:21:39 PM
Have you tried target="_blank"? That's the classic way of opening links in new tabs.

<a href="http:www.zomgwarezandpr0n.org" target="_blank" rel="noopener">Linky</a>

Tried that already, doesn't work.  I'm trying to add it to the existing menu array, so it's consistent with core code -



'logs' => array(
'label' => $txt['logs'],
'function' => 'AdminLogs',
'icon' => 'logs',
'subsections' => array(
'errorlog' => array($txt['errorlog'], 'admin_forum', 'enabled' => !empty($modSettings['enableErrorLogging']), 'url' => $scripturl . '?action=admin;area=logs;sa=errorlog;desc'),
'adminlog' => array($txt['admin_log'], 'admin_forum', 'enabled' => !empty($modSettings['adminlog_enabled'])),
'modlog' => array($txt['moderation_log'], 'admin_forum', 'enabled' => !empty($modSettings['modlog_enabled'])),
'banlog' => array($txt['ban_log'], 'manage_bans'),
'spiderlog' => array($txt['spider_logs'], 'admin_forum', 'enabled' => !empty($modSettings['spider_mode'])),
'tasklog' => array($txt['scheduled_log'], 'admin_forum'),
'settings' => array($txt['log_settings'], 'admin_forum'),
),
),

/// add support button to SMF
'community' => array(
'label' => 'SMF Support',
'function' => 'Community',
'icon' => 'community',
),

'repairboards' => array(
'label' => $txt['admin_repair'],
'file' => 'RepairBoards.php',
'function' => 'RepairBoards',
'select' => 'maintain',
'hidden' => true,
),
),





/// this function adds link to community button
function Community()
{
redirectexit('https://www.simplemachines.org/community/index.php');  // opens in same tab
// echo '<script>window.location="https://www.simplemachines.org/community/index.php"</script>';  // opens in same tab
// echo 'window.open("https://www.simplemachines.org/community/index.php", "_blank")'; // doesn't work

echo '
//<a id="anchorID" href="https://www.simplemachines.org/community/index.php" target="_blank"></a>
//<script>document.getElementById("anchorID").click()</script>';  // popup blocked

}



Looks and works fine, but opens in same tab.  >:(

Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Sir Osis of Liver

Just getting back to this, nothing I've tried works.  I can scab on a separate menu button, but that's kind of crappy and causes problems in responsive view.  Any ideas?
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Arantor

Where, exactly, are you trying to add this? Be specific, with screenshots, because this matters as to precisely how much code you need to add.

Sir Osis of Liver

#8
I'm adding it to the menu array for the new cpanel style admin menu.  It works fine, but opens in same tab.

Edit:  replaced screenshot with larger view of modded ACP.  Gotta go.
Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Pipke

in Subs-Menu.php find:

// This is a shortcut for Font-Icon users so they don't have to re-do whole CSS.
$menu_context['sections'][$section_id]['areas'][$area_id]['plain_class'] = !empty($area['icon']) ? $area['icon'] : '';


add before:

// Open link in new tab
if (!empty($area['newtab']))
$menu_context['extra_parameters'] .= '" target="_blank" rel="noopener';


in Admin.php do this as your example:

/// add support button to SMF
'community' => array(
'label' => 'SMF Support',
'function' => 'Community',
'icon' => 'community',
'newtab' => true,
),




"If something is wrong, fix it if you can. But train yourself not to worry: Worry never fixes anything."

Click here to view my mods for SMF

Hey 👋 Did i helped... you like what i do. You can now buy me a coffee! ☕

Sir Osis of Liver

Ashes and diamonds, foe and friend,
 we were all equal in the end.

                                     - R. Waters

Advertisement: