csdn文章導(dǎo)出

方法一:移除法

更新內(nèi)容:1、去除底部版權(quán)信息欄 2、新增打印頁(yè)面自動(dòng)縮放 3、去除多余無(wú)效內(nèi)容

注:如果發(fā)現(xiàn)打印預(yù)覽的時(shí)候每一頁(yè)頂部都有標(biāo)題,請(qǐng)參照下面第三步去掉“頁(yè)眉和頁(yè)腳”的勾選

(function(){
    'use strict';
    var articleBox = $("div.article_content");
    articleBox.removeAttr("style");
    $("#btn-readmore").parent().remove();
    $("#side").remove();
    $("#comment_title, #comment_list, #comment_bar, #comment_form, .announce, #ad_cen, #ad_bot").remove();
    $(".nav_top_2011, #header, #navigator").remove();
    $(".csdn-side-toolbar,.template-box,.reward-user-box,.blog-footer-bottom").remove();
    $(".p4course_target, .comment-box, .recommend-box, #csdn-toolbar, #tool-box,#dmp_ad_58, .more-toolbox, .article-info-box, .btn-readmore, .pub-footer-new").remove();
    $("aside").remove();
    $(".tool-box").remove();
    $("main").css('display','content'); 
    $("main").css('float','left'); 
    $("#mainBox").width("100%");        
    document.getElementsByTagName('body')[0].style.zoom=0.8;
    window.print();
})();

方法二:HTML重新構(gòu)建法(2020/10/31新增)

該方法與方法一功能一致,代碼更加簡(jiǎn)潔,打印完自動(dòng)還原網(wǎng)頁(yè),并且后續(xù)CSDN增加其他多余模塊也不會(huì)有影響。

(function doPrint(){      
    'use strict';
    var articleBox = $("div.article_content");
    articleBox.removeAttr("style");
    var head_str = "";       
    var foot_str = "";   
    var older = document.body.innerHTML;       
    var title= document.getElementsByClassName('article-title-box')[0].innerHTML; 
    var main_body = document.getElementsByClassName('article_content')[0].innerHTML;
    document.body.innerHTML = head_str + title + main_body + foot_str;
    $("#mainBox").width("100%");
    document.getElementsByTagName('body')[0].style.zoom=0.8;     
    window.print();
    document.body.innerHTML = older;
    return false;
})();

原文鏈接:https://blog.csdn.net/p1279030826/article/details/106602341

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容