jQuery代码阻止弹出窗口

时间:2012-12-04 03:21:03

标签: javascript jquery

以下是在线示例http://jsfiddle.net/bvJnM/ 以某种方式不会弹出linkedin配置文件。有人可以查看我的代码吗?

function excerpt(str, nwords) {
    var words = str.split(' ');
    words.splice(nwords, words.length - 1);
    return words.join(' ') + '&hellip;' + '<span>Show</span>';
}

var $div = $('.container');
$div.each(function() {
    var theExcerpt = excerpt($(this).text(), 30);
    $(this).data('html', $(this).html()).html( theExcerpt);
});

$('span').click(function() {
    var isHidden = $(this).text() == 'Show';
    var $div = $(this).parent();
    var theExcerpt = excerpt($div.text(), 30);
    $div.html( isHidden ? $div.data('html') : theExcerpt);
    $(this).remove();
});​

HTML

<script src="//platform.linkedin.com/in.js" type="text/javascript"></script>

<div class="container">
    Nulla varius diam at sem adipiscing pharetra. Integer eget nulla non purus commodo aliquam. Aenean sed nunc neque. Aliquam eleifend aliquam arcu, ac semper nulla faucibus id. Etiam luctus eleifend tempus. Vestibulum ornare, nisi vitae fermentum luctus, sem lectus rhoncus nibh, auctor iaculis magna turpis nec turpis. Aliquam orci tortor, vulputate at pretium sit amet, blandit eget libero. Sed posuere ultricies mi, sed rhoncus massa ultrices quis. Donec pulvinar vestibulum rhoncus. Donec urna lacus, mollis et convallis at, commodo nec lectus. Maecenas pretium, nunc ac volutpat tempus, dolor orci ultricies massa, eu malesuada urna massa ut orci. Duis eget elit nulla, ornare aliquet nulla. Sed eleifend scelerisque est, eu laoreet lacus ultricies id. Aenean aliquam porttitor augue, quis lacinia augue consequat vitae. Ut venenatis orci massa. Duis dignissim, justo at pellentesque adipiscing, ligula eros mollis tellus, ut accumsan lorem dui eu est.
    <p></p>
<script src="http://platform.linkedin.com/in.js" type="text/javascript"></script>
<script type="IN/MemberProfile" data-format="click" data-id="http://www.linkedin.com/in/reidhoffman"
data-format="inline"  data-text="mynamehere"></script>
扩展linkedIn链接后

无效...

1 个答案:

答案 0 :(得分:1)

好吧,让我们这样试试吧:

将文字放在p标签中并对其进行拼接切割。将脚本链接在自己的空间中并隐藏它。然后你会显示完整的文字,也会显示linkedin div。

<div class="container">
    <p>Nulla varius diam at sem adipiscing pharetra. Integer eget nulla non 
         purus commodo aliquam. Aenean sed nunc neque. </p>
<div id="lin">
    <script src="http://platform.linkedin.com/in.js" 
               type="text/javascript"></script>
<script type="IN/MemberProfile" data-format="click" 
                data-id="http://www.linkedin.com/in/reidhoffman"
data-format="inline"  data-text="mynamehere"></script>
</div>
</div>

我在这里更新了小提琴:fiddle1

编辑:工作fiddle<span>已附加到<p>,我使用$(this).parent().find('p')。它应该是$(this).parents('div').find('p')