We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4273
    • 356 Posts
    when creating a weblink to be used with dropmenu how to make it so the link to the site creates a new window ?
      SMF Bookmark Mod - check it out
      http://mods.simplemachines.org/index.php?mod=350
      • 25663 MODX Staff
      • 12,272 Posts
      Not part of the current capability, and sorely needed, I agree.
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 4041
        • 788 Posts
        I actually got this to work in etomite, and after looking at the code for the dropmenu I think my modification can be adapted to work in modx. I’ll install the newest version of modx this weekend and see what I can come up with  wink
          xforum
          http://frsbuilders.net (under construction) forum for evolution
          • 25663 MODX Staff
          • 12,272 Posts
          Sorry bugsmi0, I thought you were talking about weblink docs with new windows (which IS sorely needed). I concur that a minor hack to DropMenu would make that possible, and should probably be part of the core snippet really.

          You would need to insert code to check to see if it is a weblink or not; if it is, alter the code that outputs to put either the appropriate JS or target="_blank" into the href-tag.
            Ryan Thrash, MODX Co-Founder
            Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
            • 4041
            • 788 Posts
            This is a working version of the stock dropmenu snippet which allows weblinks to open in a new window. It works fine on my site and also still validates using the stock installed template.

            I have attached a text file ( dropmenu_weblinkNW626_1126pmest.txt) which is the snippet code, and the areas I altered are commented.
            There are a few areas of code which I copied the whole block, and the original code is marked like so:
            //orig--->

            Usage:
            when you create or edit a weblink, in the longtitle field add the target code like this:
            target="_blank"
            target="_new"
            ( I have not tested this using a javascript call yet )

            Then make sure the the Weblink field is the url you want to open in the new window.

            I’ll be doing some more testing this weekend using a javascript call but it works fine as is...
              xforum
              http://frsbuilders.net (under construction) forum for evolution
              • 4273
              • 356 Posts
              I tired this with a weblink and its not opening the URL in a new window

              i have target="_blank" in the longtitle field
              and url http://www.domain.com

              do we need to configure anything in the snippet ?
                SMF Bookmark Mod - check it out
                http://mods.simplemachines.org/index.php?mod=350
                • 4041
                • 788 Posts
                No, the only configuration option is if you want to allow weblinks to open in a new window, and it should have been set to yes.

                If you copied the text file and made it the snippet code, it should work. Perhaps you tried to copy just the modifications I made to your existing snippet, and a key piece was not added. Here are the steps I took and the places I modified just in case...

                1. add content to the end of the following query:
                $children = $modx->getActiveChildren($listParent, $orderBy, (!$orderDesc) ? 'ASC' : 'DESC', 'id, pagetitle, description, isfolder, parent, alias, longtitle, menutitle, hidemenu, introtext, content_dispo, contentType, type, template, content');


                if not the weblink content ( url to go to ) will not be present

                2. added this block which checks for the type ( document or reference ) and if new windows for weblinks is set to yes

                // Weblinks in new window
                // 6/23/06  11:50 pm est
                // check if this is a reference type document (weblink)
                // set the  $new_window_for_weblinks  to yes if you want to allow new windows
                $new_window_for_weblinks ="yes";
                
                                if($child['type']=='reference' && $new_window_for_weblinks =='yes'){
                                 $linkurl =$child['content'];
                                 $target =$child['longtitle'];
                                // weblink ahref link
                                 $link_ahref_string ='<a href="'.$linkurl.'" title="'.$child[$titleOfLinks].'" '.$target.'>';
                                }else{
                                // standard ahref link
                                 $link_ahref_string ='<a href="[~'.$child['id'].'~]" title="'.$child[$titleOfLinks].'">';
                                }


                I had to change the ahref string since the weblink is not an [~id~] link any longer

                3. In 3 areas of the code where the links are created, I added the $link_ahref_string variable, the original code is commented out like this:
                //--->
                and the new code is after the commented out original.

                  xforum
                  http://frsbuilders.net (under construction) forum for evolution
                  • 4273
                  • 356 Posts
                  I copied the entire code and renamed as DropMenuLink to try it out, everything seems to be in its place but the link doesn’t open in a new window
                    SMF Bookmark Mod - check it out
                    http://mods.simplemachines.org/index.php?mod=350
                    • 4041
                    • 788 Posts
                    To be honest I don’t have any idea why it will work for me and not for you. I even copied the code I posted and saved as DropMenuLink too and it still worked fine... since I’m really new to this sysytem, I’ll have to dig a little deeper to see where the issue lies.

                    How are you calling the snippet in the template? I have the default [ ! DropMenu ! ] setup, perhaps if you have different parameters set it is conflicting somehow. I’ll work on it and see what I can come up with huh
                      xforum
                      http://frsbuilders.net (under construction) forum for evolution
                      • 4273
                      • 356 Posts
                      I have it inside a chunk

                      [[DropMenu? &startDoc=`132`]]
                        SMF Bookmark Mod - check it out
                        http://mods.simplemachines.org/index.php?mod=350