WordPress.org

Ready to get started?Download WordPress

Forums

How to make comment links open in new window? (13 posts)

  1. 1800colette
    Member
    Posted 10 years ago #

    I'm not using the pop-up comment script by default on my blog, so links open up in my blog's frame. How can I code the wp-comments.php to make commenters' links to their sites open up in new windows (ie: target="_blank")?
    Thanks for you help!

  2. Root
    Member
    Posted 10 years ago #

    Eeek! Colette you had better brace yourself. Good luck ;)

  3. Beel
    Member
    Posted 10 years ago #

    With pop-up comments it would be a disservice to guests not to have a new browser window open up. So that the page will validate, I set rel="external" in my links and use javascript to open a browser window. You can put the following in a file called external.js and call it in the header of your page with
    <script type="text/javascript" src="external.js"></script>
    function externalLinks() {
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i=0; i
    var anchor = anchors[i];
    if (anchor.getAttribute("href") &&
    anchor.getAttribute("rel") == "external")
    anchor.target = "_blank";
    }
    }
    window.onload = externalLinks;

  4. Root
    Member
    Posted 10 years ago #

    And there goes your accessibilty and cross platform performance.

  5. Root
    Member
    Posted 10 years ago #

    And for user agents other than browsers?

  6. Anonymous
    Unregistered
    Posted 10 years ago #

    Almost 100% of my users use Netscape or IE, so I'm not worried.

  7. Root
    Member
    Posted 10 years ago #

    Poor users. And for persons on screen readers?

  8. Anonymous
    Unregistered
    Posted 10 years ago #

    Root, go back underground where you belong - you're just out to trip others up ("Well that's a joke, son"). My response shouldn't interfere with accessibility or performance. Old browsers, etc., will treat it as a "regular" link. Anyhoo, when you aim to please everyone you make compromises that please no one.

  9. Root
    Member
    Posted 10 years ago #

    As long as all our readers are clear about the consequences of the construction choices they make.

  10. WillM
    Member
    Posted 10 years ago #

    http://wordpress.org/support/3/2385
    Among others.
    I've said before that I have problems with 'rel="external"'. If you care so much about standards compliance that you are inserting unnecessary javascript to do the same thing as 'target="_blank"', what are you doing forcing people to open new windows anyway? Either embrace compliance fully or don't bother. It is actually very simple to edit wp-comments to do what this user wants, just by changing the function calls. The question is why would anyone using a standards-compliant tool like WordPress want to.

  11. Anonymous
    Unregistered
    Posted 10 years ago #

    It is compliant.

  12. MaxT
    Member
    Posted 10 years ago #

    Fully. XHTML is one thing, DOM is another, don't mix those 2... You don't mix CSS and XHTML, now do you?

  13. Root
    Member
    Posted 10 years ago #

    The point I think some folks are trying to make is that it is relatively simple matter
    to be compliant and open a new window if someone wants to. The issue is whether opening a new window at all is a good thing. Many people here aspire to slightly more than simply validating. There is absolutely no obligation to do so.
    But folks interested in the nuts and bolts of web standards, accessibility, useability, future proofing their code and all the other doo daas, generally regard new windows as a *bad thing*. You may not agree. I have a real neat piece of code which does something very similar to what you need. It is called a back button. And it is fitted to my browser already.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.