0

我正在尝试使用 XHTML 验证我的网站,我已经修复了很多错误,但有些错误一直困扰着我。在下面的代码中使用 target="_blank" 的替代方法是什么

    if($targetwindow==0){

        $openWindow='class="colorbox"';

    }elseif ($targetwindow==1){

        $openWindow='target=_self';     

    }else{

        $openWindow='target="_blank"';  

    }

echo '<a style="color:#555;" '.$openWindow.' href="'.$items["mylink"].'" '.($nofollow==1 ? 'rel="nofollow"':'').'>'.$items["mytitle"].'.....</a><br />';' 

我尝试onclick="window.open(this.href, 'OffSite').focus(); return false;在 header.php 中使用将 facebook url 链接到新窗口,它就像一个魅力,但我无法在上面的代码中做到这一点。任何人都可以帮我解决这个问题吗?或者也许相同的代码可以工作,但我不知道如何以正确的格式给出它,因为我已经尝试过了。我已经阅读了有关我的问题的相关主题,并且我也找到了答案,例如onclick="return !window.open(this.href)"但问题是放在哪里?我试过把它弄坏了网站。请帮忙!

4

1 回答 1

0

您想要的一个选项是使用这样的脚本:

    /*
 *  variables
*/
var object_links_list = document.getElementsByTagName("a");
var links_total = object_links_list.length;





/*
 *  listenners
*/
for ( n = 0; n < links_total; n++ ) {
    if ( "rel" in object_links_list[n] ) {
        if ( object_links_list[n].rel === "external" ) {
            if ( object_links_list[n].addEventListener ) {
                object_links_list[n].addEventListener( 'click', open_external_link, false );
            } else if ( object_links_list[n].attachEvent ) {
                object_links_list[n].attachEvent( 'click', open_external_link );
            }
        }
    }
}





/*
 *  Function to open links in a new window/tab
*/
function open_external_link() {
    window.open( this.href, '_blank' );
    this.setAttribute('href','');
    if ( this.stopPropagation ) {
        this.stopPropagation();
    } else {
        this.cancelBubble = true;
    }
    return false;
}

而 xhtml 将是这样的。

    <a href="http://www.example.com/" title="your_title" rel="external">link text</a>
于 2014-02-01T08:59:35.450 回答