target=”_blank” for primary links(drupal 5.5)

最近主站(extjs.org.cn)新开了一个论坛,在主页的 primary links 上新加了一个 links ,是链接到论坛的.但drupal默认是不能设置其中一个以 target=”_blank” 方式打开一个新窗口的,查看了一下模板primary links部分的代码.

<!--p if (isset($primary_links)) {-->
<!--p print theme('links', $primary_links, array('class'-->'primary_links')) ?&gt;
<!--p }-->

其实我们要做的也很简单,想法就是以http开头的都以新的窗口形式打开.也就是把生成后的源代码将 ‘href=”http://’ 替换成 ‘target=”_blank” href=”http://’就可以了. 以下是简单修改后的代码.

<!--p if (isset($primary_links)) {-->
<!--p $primary_links_str = theme('links', $primary_links, array('class'-->'primary_links')) ?&gt;
<!--p print str_replace( 'href="http://', 'target="_blank" href="http://', $primary_links_str);-->
<!--p }-->

其他模板的写法可能会有一些不一样,但思路是一样的.
就是在链接输出前将 http://开头的链接前面加上 target=”_blank”.

注意事项:
1,修改对应模板目录下面的 page.tpl.php 文件.
2,在输出之前将它替换掉.
3,要在新窗口打开的链接必须写完整的url.即以http://extjs.org.cn/sitemap.html 这样的形式. /sitemap.html 这样是解析不了的.

This entry was posted in 网站应用 and tagged , , . Bookmark the permalink.

One Response to target=”_blank” for primary links(drupal 5.5)

  1. judy says:

    版主您好~
    想与您询问相关问题~照著您的方式制作一次~
    但效果出不来~不知是我那错了~想跟您请教~>w<谢谢

    ‘pages’)); ?>

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word