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.

Open external links in a new window? (target="blank"?)

blizeHblizeH ✭✭
edited February 2010 in Vanilla 2.0 - 2.8
Hey guys,

A lot of users on the forum I run have requested that windows open in a new window (IE users eh!) when you click on them.

I thought I could easily amend the anonymize plugin to do this:
$("a:external").attr("href", function () {
// ... prepending the prefix to the original value
return prefix + $(this).attr("href") + ' target="blank"';
... but of course this just changes the actual address, not the a tag! :( Any suggestions please? I've had a look through the core PHP files and couldn't really see anything relating to it.



  • MarkMark Vanilla Staff
    How about this:

    $("a:external").attr("target", 'blank');
  • Boy oh boy do I ever suck at jQuery, thank you so much Mark, and apologies for asking such a silly/simple question! :-)
  • MarkMark Vanilla Staff
  • edited May 2010
    never mind.
  • Hi Mark,

    Thanks for the tip. I am new to Vanilla. Just set it up within iframe of my site and the links are not opened in a new window. Where do I add your line of code to maek this happen? Thanks.

  • sahotataransahotataran Developer, Bay Area - CA ✭✭✭

    this is a jquery line and will go in any javascript files or in your page - if you are familiar with jquery

    There was an error rendering this rich post.

  • Thanks sahotataran. I haven't used JQuery, but other JS libararies. I see Vanilla deployed with jquery in the js folder. Is index.php a good place to put this code? I don't see any in that file. Should I create a conf/bootstrap.after.php to add this custom code?

  • sahotataransahotataran Developer, Bay Area - CA ✭✭✭

    no. you use your theme for adding additional code.

    open /themes/yourtheme/views/default.master.php or default.master.tpl - you can add the above code in head using

    < script type="text/javascript" > $(document).ready(function() {
       $("a:external").attr("target", 'blank');
    < /script>

    There was an error rendering this rich post.

  • Great. Thanks! You pointed me to the right direction. Looks like there are some reading for me to do regarding to the customization of Vanilla.

  • reminds me that whenever i add jquery to the default.master.tpl it bonks out :/

  • 422422 Developer MVP

    as in jquery.js ? its already loaded though @redtwentyfour

    There was an error rendering this rich post.

  • nono, i mean whenever i add any jquery code

  • 422422 Developer MVP

    Always add it to the footer

    If you try and render jquery before jquery.js loads it will fail

    There was an error rendering this rich post.

  • edited December 2011

    Hmm, tried both to add it in either <div id="Foot"> or <head> but not working. I don't have customized theme. There is one "EmbedFriendly" in the folder, so added in EmbedFriendly/views/default.master.tpl. I tried to just put alert('hi') but it did nothing. Doesn't seem like this file is loaded?

  • sahotataransahotataran Developer, Bay Area - CA ✭✭✭

    Probably issue with including file. The file is not at URL at which it was included probably

    There was an error rendering this rich post.

  • ToddTodd Chief Product Officer Vanilla Staff

    You want to put javascript between {literal}..{/literal} tags if you are using smarty. Otherwise it will interpret your javascript curly braces as smarty tags.

Sign In or Register to comment.