Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Add menu item - Open in same window ?

Anyway to make the link open in the same window ?

Comments

  • My bad. How to open in different windows ?

  • vrijvlindervrijvlinder Papillon-Sauvage MVP

    you can use a small bit of jquery to do that

    here are some examples of what you can do using this , the #Menu a is the one that does it for menu links

    <script type="text/javascript"> 
    
    $(document).ready(function() {
    
    $('.MessageList a').attr('target', '_blank');
    $("#Menu a").attr("target", '_blank');
    $(".AptAdImg a").attr("target", '_blank');
    $(".Attachment a").attr("target", '_blank');
    $(".Meta a").attr("target", '_self');
    $('#Foot #Menu li:last > a').attr("target", '_blank');
    $('#Menu ul li:last-child > a').popup();
    $('#Foot #Menu li.Messagelink a').popup();
    $('#Foot #Menu li:last > a').popup();
    $('span.onebit_mp3 a').attr("target", '_blank');
    $("a.ReactButton.Quote.Visible").attr("target", '_self');
    $("form#Form_Comment").dropzone({ url: "/forum/vanilla/post/comment" });
    });
    </script>
    
  • @‌ vrijvlinder

    Unfortunately, I'm stuck. For example: Menu Link No.1 - I would like that when I press on it a new tab will open with google.com
    Which code and where do I have to insert it?

    Thanks for your help in advance....

  • vrijvlindervrijvlinder Papillon-Sauvage MVP
    edited December 2014

    you would use children

    $('#Menu li:first-child > a').attr("target", '_blank');

    $('#Menu li:nth-child(2)> a').attr("target", '_blank');

    $('#Menu li:nth-child(3)> a').attr("target", '_blank');

    $('#Menu li:last-child > a').attr("target", '_blank');

    http://api.jquery.com/nth-child-selector/

  • Thx for your try to help me. But to be honest. I am not a scripter/coder. I have no idea where to insert this. Can you upload a demo .php file where I can have a look.... with the example www.google.com.

    I think than I would understand....

  • 1)

    in default.php

    change this
    public function Base_Render_Before($Sender) {

    to this

    public function Base_Render_Before($Sender) {
    
             $Sender->AddJsFile($this->GetResource('js/addmenuitem.js', FALSE, FALSE));
    

    2)

    in the AddMenuItem folder add a subfolder called js

    /AddmenuItem/js

    create a file in the /AddmenuItem/js/addmenuitem.js

    called addmenuitem.js

    in addmenuitem.js put this code

    jQuery(document).ready(function($) {
    
    // add a blank to Google in Sub menu  the name of the Menu Item
    $('.sub-menu:contains("Google")').attr("target", '_blank');
    
    });
    

    since vanilla core does not allow you to add target attributes via addlink, this is the way to do it with this plugin.

    otherwise simply add the link with target to your .tpl file.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • I made it! :)

    Thx you very very much @peregrine and also @vrijvlinder for your support.

  • peregrineperegrine MVP
    edited December 2014

    if you want ALL the menu links that were specifically added via with add menu item plugin

    you can change the code to this.

    $('.sub-menu').attr("target", '_blank');

    and all the links that are in the add menu item settings will have external pages.

    you also received the Namensgenerator badge :)

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • title could be change to

    Open menu items in a Different Window.

    by a moderator.

    would make the discussion easier to find.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

Sign In or Register to comment.