在新窗口中打开外部链接

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在新窗口中打开外部链接相关的知识,希望对你有一定的参考价值。

There are many ways to have jQuery open external links for you. Some depend on relative URL's for internal links and absolute URL's for external links. Some analyze the link to see if it matches your domain. These are great but can sometimes be confusing for those new to jQuery and web development. There is a quick way that you can use and the only requirement is add 'ext' to the [rel] attribute...
  1. $(document).ready (function() {
  2. // Activate on links with rel attribute set to ext
  3. $('a[rel=ext]').click (function() {
  4. // Add target=_blank attribute to link when clicked
  5. $(this).attr('target','_blank');
  6. });
  7. });
  8.  
  9. /* Usage
  10.  * simply write your links like this:
  11.  * <a href="url_here" rel="ext" title="title_here">LINK TEXT</a>
  12.  */

以上是关于在新窗口中打开外部链接的主要内容,如果未能解决你的问题,请参考以下文章

JavaScript 在新窗口中打开外部链接

在新窗口中打开外部链接

在新窗口中打开外部链接

在新窗口中打开外部链接

JavaScript jQuery在新窗口中打开外部链接

自动在新窗口中打开每个外部链接(html、css)