Open menu links in new window

fuz2013

Joined: 2013-02-06
Posts: 10
Posted: Sat, 2014-06-14 23:56

hoping someone can help me accomplish this..
I am using custom menus module, really works great,
But to bad it only opens links in the same window,
i need it to open links in new windows.

Can anyone help me with this or share some ideas for another modules that will.

thanks

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Sun, 2014-06-15 17:12

Not specific to the menu links module but http://codex.galleryproject.org/Gallery3:Modules:exlinks_new_window
will work if the links are external.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
fuz2013

Joined: 2013-02-06
Posts: 10
Posted: Sun, 2014-06-15 19:54

thanks for the reply Dave,
yes i have that module installed as well,
But it does not work with links added to the custom menu module.
(i use the "no right click" module also which kills the right click menu)

i added 2 external links so far that i need to have open in a new window.
is there a part of the code that i can edit to force links to open in a new window for menus ?
thanks

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Sun, 2014-06-15 22:34

It works for me for the menu (as long as they are external links). Not sure why it does not for you.

how familiar are you with jquery? I can't seem to see how the just add a 'target=' to the menu links code.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
fuz2013

Joined: 2013-02-06
Posts: 10
Posted: Sun, 2014-06-15 23:33

thanks Dave,
for example, i have a Forum and FAQ set up on my server, that I tried to link to using the full url.
but maybe those are getting misinterpreted by the exlinks_new_window module.
or does the links have to be totally "off site" for exlinks_new_window module to work ?

i am only familiar with html, but try to get around things if i can when it comes to code.
like if i was told what to change and where it is i can lol. but that's the extent of it.
if i seen reference to a 'target=' id know how to change it.

jquery searches suggest to use this code:
$('a[href^="http://"], a[href^="https://"]').attr('target', '_blank');
but id have no clue where to try it.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Mon, 2014-06-16 00:05

Yes the eternal links in new window module need to be "off site"

So what you can do is:
use the attached to replace the original in the menu links module. You will have to rename it to the proper extension.
I added css_id to the menu links.
Then use some jquery to the bottom of page.html.php of the theme you are using just before the </body> tag:

    <script>
    $(document).ready(function(){
      $('a[id^="custom_menu"]').attr("target", "_blank");
    });
    </script>

What it does is looks for all links (a) that have a id that starts with custom_menu and changes the target attribute to _blank.

Dave
____________________________________________
Blog & G2 || floridave - Gallery Team

 
fuz2013

Joined: 2013-02-06
Posts: 10
Posted: Mon, 2014-06-16 00:45

Hey Dave,
thanks for trying to help.
i have done as you suggested, its "half" working now.

the links i add to the custom menu open in new window (which is what i want)
but for some reason i can only add 1 link.?

even if i add 5 items with 5 links only 1 shows in the menu.
the other 4 names and links vanish and do not show. but do show under configuration where i add them.
any ideas ?

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Mon, 2014-06-16 01:22

Did it work before any modifications?

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
fuz2013

Joined: 2013-02-06
Posts: 10
Posted: Mon, 2014-06-16 01:40

hi Dave,
i fixed the problem and all works perfect now.
All it took was adding this code:

<script>
    $(document).ready(function(){
    $('a[href^="http://"], a[href^="https://"]').attr('target', '_blank');
    });
</script>

to the "themes/wind/views/page.html.php", did not need to change the custom_menus_event.php file at all.
(i restored to original file then added the script piece above)
all the custom menu links i add now open in new window,
and the normal album links opening in same window.

thanks for your help Dave.

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Mon, 2014-06-16 04:42

Glad you got it sorted.
I did find the issue in the above attachment and updated the file.

Your fix will work as well but all links that have a http in the a will open in a new window not just the menu links.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
fuz2013

Joined: 2013-02-06
Posts: 10
Posted: Mon, 2014-06-16 05:58

Thanks Dave,
I saved the file again,
will give it a try tomorrow and let you know how it goes.

Odd though as i tried the normal album links and image links,
even my random image, all opened in same window like normal.
and only my custom menu links opened in new windows.

 
fuz2013

Joined: 2013-02-06
Posts: 10
Posted: Mon, 2014-06-16 18:57

thanks for the help Dave,
works perfect. =)