• Im using that chenpress setup making posts and I am trying to find a way to make the default URL link go to a blank window for all the links that are in my blog posts. I know I can add my own code to make the default period go to new but that even makes my categories and everything do new. Any way I can do this? Thank you!

Viewing 5 replies - 1 through 5 (of 5 total)
  • A couple solution can be found here:

    http://wordpress.org/support/topic/41168#post-231398

    With a few small changes the javascript option (which is probably closer to what you want, since it can filter out “local” links on the page by domain) could be modified to work without the checkbox option, though I’m not one to recommend that.

    Thread Starter Skettalee

    (@skettalee)

    Im sorry but that just really confused me. None of what was on that link seemed that it would work and I dont think id know where to put or no how to edit those codes. Any help with that?

    “I know I can add my own code to make the default period go to new”

    I took this to mean you at least understood the basics of what you’re trying to do. Perhaps we should start at the start: you want links in your posts (at the very least) to open in a new browser window, correct? There are a few reasons why this is not the best of ideas, but if you’re going to do it, you do have several alternatives:

    1. Place the following attribute in every <a> tag you place in a post:

    target="_blank"

    Issues with this is it’s invalid XHTML, and must be added manually (although one could edit the link Quicktag to insert it automatically).

    2. Place the following attribute in every <a> tag you place in a post:

    onclick="window.open(this.href,'_blank');return false;"

    There are other javascript-ish methods; this is probably the simplest. Again, it must be added manually (same Quicktag caveat as for 1), but it is at least valid XHTML.

    3. Use something like the following javascript in your template(s):

    http://www.js-examples.com/javascript/?view=848

    This automatically rewrites links on a page, with the side benefit of being able to exclude links within your domain (i.e. “www.337studios.com”), and to offer an option to readers to turn it on and off. It is however another XHTML bad boy, though this can be dealt with in the code.

    4. Use something like my Add Link Attribute plugin:

    http://guff.szub.net/add-link-attribute/

    *Wrapping* a WP template tag in this function allows you to pass one or more attributes, such as ‘target=_blank’, to any links output by that tag. So you could replace this in your templates:

    <?php the_content(); ?>

    with:

    <?php add_link_attr('the_content', '',
    'onclick="window.open(this.href,'_blank');return false;"'); ?>

    and the plugin slips the onclick attribute into every link. But note this does not offer the ability to filter out those “local” links of yours.

    If you decide on the best way for your to go on this but need further help, just ask (just make sure to clarify what that way is going to be).

    Thread Starter Skettalee

    (@skettalee)

    I understand better now but yeah I guess ill just do without. I can understand why its not good. I GUESS. I just really dont like other sites closing my site when users are on my site.

    I wanted to have my links go to a new browser window, while avoiding crazy javascript and still validating XHTML. I found the solution via either the Webstandards or Designers In House list (I think the latter).

    I link to an external javascript in the head of the document. It simply contains:

    function externalLinks() {
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName(“a”);
    for (var i=0; i<anchors.length; i++) {
    var anchor = anchors[i];
    if (anchor.getAttribute(“href”) &&
    anchor.getAttribute(“rel”) == “external”)
    anchor.target = “_blank”;
    }
    }
    window.onload = externalLinks;

    And then I set the default value of links to rel=external

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Making default new target links?’ is closed to new replies.