2010-06-18 68 views
0

如果我在可点击区域放置rel =“external”的新插件中使用jquery装*插件,但是点击链接打开2次, 如何解决这个问题?在jquery插件中使用rel external打开链接2次

例如: 我有:

<p> 
text <a rel="external" href="/link">text2</a> 
</p> 

文本打开完美的一次,但单击文本2的链接打开两次

代码:

if(typeof jQuery != 'undefined') { 
    jQuery(function($) { 
     $.fn.extend({ 
      fitted: function(options) { 
       var settings = $.extend({}, $.fn.fitted.defaults, options); 

       return this.each(
        function() { 

         var $t = $(this); 
         var o = $.metadata ? $.extend({}, settings, $t.metadata()) : settings; 

         if($t.find(':has(a)')) { 
          /** 
          * Find the first Anchor 
          * @var object $a 
          */ 
          var $a = $t.find('a:first'); 

          /** 
          * Get the Anchor Attributes 
          */ 
          var href = $a.attr('href'); 
          var title = $a.attr('title'); 

          /** 
          * Setup the Container 
          * Add the 'container' class defined in settings 
          * @event hover 
          * @event click 
          */ 
          $t.addClass(o['class']['container']).hover(
           function(){ 
            /** 
            * Hovered Element 
            */ 
            $h = $(this); 

            /** 
            * Add the 'hover' class defined in settings 
            */ 
            $h.addClass(o['class']['hover']); 

            /** 
            * Add the Title Attribute if the option is set, and it's not empty 
            */ 
            if(typeof o['title'] != 'undefined' && o['title']===true && title != '') { 
             $h.attr('title',title); 
            } 

            /** 
            * Set the Status bar string if the option is set 
            */ 
            if(typeof o['status'] != 'undefined' && o['status']===true) { 
             if($.browser.safari) { 
              /** 
              * Safari Formatted Status bar string 
              */ 
              window.status = 'Go to "' + href + '"'; 
             } 
             else { 
              /** 
              * Default Formatted Status bar string 
              */ 
              window.status = href; 
             } 
            } 
           }, 
           function(){ 
            /** 
            * "un"-hovered Element 
            */ 
            $h = $(this); 

            /** 
            * Remove the Title Attribute if it was set by the Plugin 
            */ 
            if(typeof o['title'] != 'undefined' && o['title']===true && title != '') { 
             $h.removeAttr('title'); 
            } 

            /** 
            * Remove the 'hover' class defined in settings 
            */ 
            $h.removeClass(o['class']['hover']); 

            /** 
            * Remove the Status bar string 
            */ 
            window.status = ''; 
           } 
          ).click(
           function(){ 
            /** 
            * Clicked! 
            * The Container has been Clicked 
            * Trigger the Anchor/Follow the Link 
            */ 
            if($a.is('[rel*=external]')){ 
             window.open(href); 
             return true; 
            } 
            else { 
             //$a.click(); $a.trigger('click'); 
             window.location = href; 
            } 
           } 
          ); 
         } 
        } 
       ); 
      } 
     }); 

     /** 
     * Plugin Defaults 
     */ 
     $.fn.fitted.defaults = { 
      'class' : { 
       'container' : 'fitted', 
       'hover' : 'hovered' 
      }, 
      'title' : true, 
      'status' : true 
     }; 
    }); 
} 

*: http://www.trovster.com/lab/plugins/fitted/

如何解决这个问题?可以修复?

非常感谢你

回答

1

解决:

这样的:

if($a.is('[rel*=external]')){ 
      window.open(href); 
      return true; 
      } 

此:

if($a.is('[rel*=external]')){ 
      window.open(href); 
      return false; 
      } 
0

我认为实际上是能够在点击使用其他功能这是这样做的:

.click(function(e){ 
    e.preventDefault(); 
    if($a.is('[rel*=external]')){ 
    window.open(href); 
    } else { 
    window.location = href; 
    } 
});