Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID Sign In with Twitter

Categories

In this Discussion

Who's Online 11

CurtisOdensarowlwp422 +8 guests

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

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.

Cheers

Comments

  • Posts: 4,883
    How about this:

    $("a:external").attr("target", 'blank');
  • Posts: 840
    Boy oh boy do I ever suck at jQuery, thank you so much Mark, and apologies for asking such a silly/simple question! :-)
  • Posts: 4,883
    :P
  • Posts: 1
    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.

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

    Theme Charcha for great desktop and mobile experience! - drop me a message :)

  • 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?

  • Posts: 599 2 likes

    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>

    Theme Charcha for great desktop and mobile experience! - drop me a message :)

  • Posts: 4 1 like

    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
    Posts: 2,094

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

    ♥ I love Vanilla. VanillaSkins | on Twitter | on Facebook | Available Freelance | Take the Vanilla Test | Free Downloads

  • nono, i mean whenever i add any jquery code

  • 422422
    Posts: 2,094

    Always add it to the footer

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

    ♥ I love Vanilla. VanillaSkins | on Twitter | on Facebook | Available Freelance | Take the Vanilla Test | Free Downloads

  • 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?

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

    Theme Charcha for great desktop and mobile experience! - drop me a message :)

  • Posts: 1,584

    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.

    Vanilla co-founder

Sign In or Register to comment.