Hide buttons when printing

前端 未结 3 725
醉梦人生
醉梦人生 2021-02-02 13:14

I have a page which contains at the bottom 3 buttons with the following coding:

3条回答
  •  囚心锁ツ
    2021-02-02 14:07

    Assign an id to the other 2 buttons. For the POST NEWS button you can set id to postnews and RE-ENTER THE NEWS to reenterthenews; Then do this

    function printpage() {
    
        //Get the print button and put it into a variable
        var printButton = document.getElementById("printpagebutton");
        var postButton = document.getElementById("postnews");
        var reenterButton = document.getElementById("reenterthenews");
    
        //Set the button visibility to 'hidden' 
        printButton.style.visibility = 'hidden';
        postButton.style.visibility = 'hidden';
        reenterButton.style.visibility = 'hidden';
    
        //Print the page content
        window.print()
    
        //Restore button visibility
        printButton.style.visibility = 'visible';
        postButton.style.visibility = 'visible';
        reenterButton.style.visibility = 'visible';
    
    }
    

    HTML

提交回复
热议问题