• Hi,

    I wonder where to add target=”_blank” to have author’s links in the comments to open in a new windows instead as default (the same windows).

    // Micke

Viewing 8 replies - 1 through 8 (of 8 total)
  • Try not to use the target attribute, as it’s not valid XHTML.

    Place the following script in somewhere in the head tags:

    function makeNewWindows() {
    if (!document.links) {
    document.links = document.getElementsByTagName('a');
    }
    for (var t=0; t<document.links.length; t++) {
    var extlinks = document.links[t];
    if (extlinks.href.search(/http/) != -1) {
    if (extlinks.href.search('/DOMAIN/') == -1) {
    extlinks.setAttribute('target', '_blank');
    }
    }
    }
    }
    window.onload = function(e) {makeNewWindows();}

    Replace DOMAIN with whatever the domain name for your site is, this should open all external links in a new window – note: ALL external links!

    Cheers,
    Michael.

    Thread Starter mickej

    (@mickej)

    “target” is not valid XHTML, r u kidding me? So this is the easiest way to do it? omg

    Well, it works fine.

    Thx!

    Edit: I tried to validate, and the validator does not complain about the target=”_blank” tags…

    It is deprecated in HTML, but it will still work, if you validate your document at XHTML 1.0 Strict or XHTML 1.1 it will fail.

    They will work in most browsers, so you can do as you wish.

    Thread Starter mickej

    (@mickej)

    Well, your script worked fine! Thx very much!

    On what page should that code be placed? On the comments page or the main wordpress page?

    Place the following script in somewhere in the head tags:

    Which means usually the header.php file of your theme.

    Okay, thanks. I’m learning one day at a time ??

    I tried the JavaScript code in my header.php and it works great! But I can not get it to validate…
    InValid XHTML

    Placed right after the </style>

    <script type="text/javascript">
    function makeNewWindows() {
    if (!document.links) {
    document.links = document.getElementsByTagName('a');
    }
    for (var t=0; t<document.links.length; t++) {
    var extlinks = document.links[t];
    if (extlinks.href.search(/http/) != -1) {
    if (extlinks.href.search('bluetoothwirelesslife.com') == -1) {
    extlinks.setAttribute('target', '_blank');
    }
    }
    }
    }
    window.onload = function(e) {makeNewWindows();}
    </script>

    Any ideas on how to validate the javascript?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Comment author’s links’ is closed to new replies.