新浪微博网页如何共享四个单词,将页面标题链接显示为标题?

时间:2018-01-21 07:27:01

标签: javascript php

将此页面更改为标题: enter image description here

与此相似: enter image description here

1 个答案:

答案 0 :(得分:0)

 $('.share_weibo,.share_haoyou,.share_qzone').click(function () {
    var url = '';
    var newsurl = location.href;
    var title = document.getElementsByTagName('h1')[0].innerText;
    var desc = document.getElementsByName('description')[0].content ? document.getElementsByName('description')[0].content : '' ;
        desc = cat_str(desc,80);
    var weibo_title = encodeURIComponent('【'+ title.replace(/ /g, " ").replace(/<br \/>/g, " ") + '】' + desc.replace(/ /g, " ").replace(/<br \/>/g, " ") +'@xxx');    
    var picurl = document.getElementById('gb_article_body').getElementsByTagName('img')[0] ? document.getElementById('gb_article_body').getElementsByTagName('img')[0].src : '';
    switch ($(this).attr('class')) {
        case 'share_weibo js_share':
            url = 'http://service.weibo.com/share/share.php?url=' + newsurl + '&title=' + weibo_title + '&appkey=xxxxxxxx&pic=' + picurl + '&searchPic=true';
            break;
        case 'share_tengxun js_share':
            url = 'http://share.v.t.qq.com/index.php?c=share&a=index&url=' + newsurl + '&title=' + title + '&appkey=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
            break;
    }
    window.open(url);
});