0

整天都在努力寻找解决方案,这让我发疯。我有一个通过 XSLT 编译的页面,当我单击 Twitter 社交链接以共享有关文章的详细信息时,它会为该类的每个实例打开一个新窗口,而不仅仅是单击的那个。

请您查看以下页面并单击其中一个 Twitter 链接:

http://search.stoneburndemo.com/search?q=a&btnG.x=-564&btnG.y=-178&filter=0&daterange_ddm=all&as_q=&site=default_collection&client=alhayat_production&output=xml_no_dtd&proxystylesheet=alhayat_production&lr=lang_ar&oe=UTF-8&ie=UTF-8&ud= 1&proxyreload=1&sort=date%3AD%3AL%3Ad1&exclude_apps=1&tlen=88

这是我正在使用的代码:

<script>
$('.twitter_sl').find('a').css('cursor', 'pointer');
$('.twitter_sl').children('a').click(function(){

var twitterOrigURL = $(this).attr('title').replace(/\%20/g, '%2520'),
    twitterURL = twitterOrigURL,
    twitterText = $(this).attr('name');

window.open('http://www.twitter.com/share?text='+twitterText+'&amp;url='+twitterURL,'_blank', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=250,width=600');
});
</script>

HTML 标记是:

<td class="twitter_sl">
<a title="{$full_url}" name="{T}"><img src="http://daharchives.alhayat.com/images/t_logo.png" alt="Share on Twitter" height="25px" width="25px"/></a>
</td>

这个问题在 Chrome 中有些隐藏,因为它似乎阻止了除了一个弹出窗口之外的所有窗口。Firefox 通过不阻止任何窗口并打开 10 个新窗口来最好地突出这个问题。

4

2 回答 2

2
  1. 你应该在 CSS 中保留表现性的东西。在你的样式表中做一个规则 .twitter_sl { cursor: pointer; }

  2. 您可以将点击事件修改为更精细,如下所示:

    $('.twitter_sl > a').on('click', function(){
        var that = $(this),
            twitterOrigURL = that.attr('title').replace(/\%20/g, '%2520'),
            twitterText = that.attr('name');
    
        window.open('http://www.twitter.com/share?text=' + twitterText + '&amp;url=' + twitterOrigURL, '_blank', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=250,width=600');
    });
    

编辑:这是一个小提琴,它在 FF 中工作得很好。http://jsfiddle.net/5nC4q/3/

于 2013-04-23T18:51:06.607 回答
0

我想通过使用 .each() 迭代链接,每个链接都有其“自己的点击”

<script>
$('.twitter_sl').find('a').css('cursor', 'pointer');
$('.twitter_sl').children('a').each(function(){

$(this).click(function(){

var twitterOrigURL = $(this).attr('title').replace(/\%20/g, '%2520'),
twitterURL = twitterOrigURL,
twitterText = $(this).attr('name');

window.open('http://www.twitter.com/share?text='+twitterText+'&amp;url='+twitterURL,'_blank',      'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=250,width=600');
});
});
</script>
于 2013-04-23T18:46:58.157 回答